DYNAMIC MEMORY MANAGEMENT
Active In SP
Joined: Jun 2010
08-10-2010, 10:25 AM
DYNAMIC MEMORY MANAGEMENT.doc (Size: 41.5 KB / Downloads: 76)
DYNAMIC MEMORY MANAGEMENT
String processing requires memory to be allocated for string storage. New strings may be input or created, old strings discarded, and strings in general may expand or contract during this processing. This requires some means of allocating storage in segments of variable size, and "recycling" unused space for new data.
The Forth language has only two structures for allocation and de-allocation: the dictionary, and the stack. Both of these are Last-In First-Out allocators, releasing memory only in the reverse order of its original allocation.
Since this is an unacceptable restriction, patternForth requires a dynamic memory manager.
There are four design criteria for a memory allocator.
a) Efficiency of representation. Data should be stored in a form which can be efficiently processed by the end application.
b) Speed of allocation. The time involved to obtain a new segment of memory would preferably be finite and deterministic; ideally, short and invariant.
c) Speed of "recycling". Likewise, the time make a segment of memory available for re-use, would preferably be finite and deterministic; ideally, short and invariant.
d) Utilization of memory. The amount of memory which is made available for data should be maximized. This implies:
* memory should be "parceled out" in such a manner as to minimize "wasted space";
* the allocator should use as little storage as possible for its own internal data;
* the amount of memory which is made available through recycling should be maximized. Ideally, storage which is recycled should be completely re-usable. This is particularly significant since the allocate-recycle- allocate cycle will repeat endlessly.
A memory allocator should solve, or at least address, the problem of "fragmentation." This is the division of memory so as to leave small, unusable segments.
All memory managers represent a tradeoff among these four criteria. The Patternforth memory manager design weighted them as follows:
a) Efficiency of representation. We decided that each string would be stored in a contiguous block of memory. The machine-level string operations which are available (on the 8086) are much more suited to incrementing pointers than traversing linked lists.
b) Speed of allocation. The time required to allocate a segment of memory could be variable, but bounded. We desired an "upper limit" on the search time for a suitable segment.
c) Speed of "recycling". The time involved to recycle a segment of memory could be variable, but bounded. In particular, we wished to avoid the often-seen problem of halting for several seconds while memory is consolidated.
We valued recycling over allocation. We strongly desired a recycling scheme whose time is short and fixed.
d) Utilization of memory. This was the least emphasized of the four criteria. Since we anticipated the use of long strings, we favored schemes having a "fixed" overhead (X bytes per string), as opposed to a "variable" overhead (X bytes per character).
Active In SP
Joined: Feb 2012
05-03-2012, 09:20 AM
to get information about the topic memory management full report ppt and related topic refer the link bellow
Joined: Apr 2012
29-09-2012, 01:13 PM
POINTERS AND DYNAMIC MEMORY MANAGEMENT
Pointers.pptx (Size: 183.21 KB / Downloads: 15)
Pointers are one of the most important features of C++ language. Pointers need very careful handling. There are many reasons for using pointers.
A pointer allows a function or a program to access a variable outside the preview of function or program.
Use of pointer increases makes the program execution faster.
Using pointers, arrays and structures can be handled in more efficient way.
To communicate with operating system about memory.
ACCESSING ADDRESS OF A VARIABLE
The actual address of a variable is system dependent. During compilation and linking, addresses are assumed to be relative to some base address, usually 0. When the operating system loads the program in a free block, all the address are transformed with relative to address of the first memory location of the free block.
Consider the following statement :
Possible problems with the use of pointers
The most common problem with pointers is that the programmer fails to initialize a pointer with a valid address. Such an initialized pointer, referred to as dangling/wild pointer, can end up pointing anywhere in memory that may include the program code itself or to the code of the operating system. When the system stop responding, we say the system has hanged up and the only option left is to reboot the system. Therefore, care must be taken to initialize pointers with valid address.