void* malloc(size_t nbytes); void free(void* ptr);There are various issues associated with allocation of memory.
realloc() routine. The size of an already allocated
buffer is extended using this routine.
free. This allows partial freeing.
void* MemAlloc(int n)
n and return a pointer to it.
Return NULL on error.
int MemFree(void* ptr)
ptr. The routine returns
the size of the freed region. If ptr does not correspond to a
memory object created by MemAlloc, the routine should return
-1.
struct memStat* GetStat(void)
struct memStat {
int memAllocated;
/* total size of the memory allocated */
int memFree;
/* total size of free regions */
int minFree;
/* size of the smallest free region */
int maxFree;
/* size of the largest free region */
int numFrag;
/* number of fragments in the free region */
}
public/p3 on
"ieng9".
Some allocators keep track of memory allocation information (size, etc.) in extra data structures. Can this information be stored in the memory pool itself? For example, instead of allocating and returning memory, the allocator stores the bookkeeping information in the allocated memory itself. (The size of the allocated region is the size requested + the size of the header.)
ptr ===>+----------------+ +----------------+
| | | header info. |
| allocated | | (size, etc.) |
| memory | ptr ===>+----------------+
| | | |
| | | allocated |
+----------------+ | memory |
| |
| |
+----------------+
Each scheme has its advantages and disadvantages.
memAlloc.c. You should tar
your source files, header files, your driver code, and the Makefile to
memAlloc.tar. Use bundleP3 to submit the code
before 11:59 PM on May 19, 2000.
You should submit your report (of around 8 pages) to Allen Chu during his office hours on May 19, 2000.