PDA

View Full Version : how to write malloc function



mthalis
November 16th, 2007, 04:04 AM
I'm in big trouble. I want to write malloc() function in language C. I want to write 'new malloc' function it do same thing in original malloc function do. This is my question

Write your own replacements for the memory allocation/deallocation routines malloc() and free(). Name these two new functions NewMalloc() and NewFree(). These two functions should be implemented in a file called newmalloc.c. Make sure to use the exact spellings as given above for the functions as well as the file. NewMalloc() allocates memory for each call from an array of fixed size. This array is an array of 50,000 characters. All the data structures that you declare to manage this 50,000 bytes memory area must reside within that memory area. The memory allocated using NewMalloc() can be freed with NewFree(). You cannot use malloc() or free() to write these two new functions. If memory cannot be allocated using the available memory a suitable error value must be returned. The funtion prototypes of NewMalloc() and NewFree() should be the same as of malloc() and free().

This is my original question if anyone give some answer it's great help to me. I want it as soon as posible.

akniss
November 16th, 2007, 04:40 AM
I'm in big trouble. I want to write malloc() function in language C. I want to write 'new malloc' function it do same thing in original malloc function do. This is my question

Write your own replacements for the memory allocation/deallocation routines malloc() and free(). Name these two new functions NewMalloc() and NewFree(). These two functions should be implemented in a file called newmalloc.c. Make sure to use the exact spellings as given above for the functions as well as the file. NewMalloc() allocates memory for each call from an array of fixed size. This array is an array of 50,000 characters. All the data structures that you declare to manage this 50,000 bytes memory area must reside within that memory area. The memory allocated using NewMalloc() can be freed with NewFree(). You cannot use malloc() or free() to write these two new functions. If memory cannot be allocated using the available memory a suitable error value must be returned. The funtion prototypes of NewMalloc() and NewFree() should be the same as of malloc() and free().

This is my original question if anyone give some answer it's great help to me. I want it as soon as posible.

Which class is this for? :)

mthalis
November 16th, 2007, 05:53 AM
it header include only <stdio.h> thats what I want but if can't use it you can use anything you want. please send anser less than one hour.

David Corrales
November 18th, 2007, 03:50 AM
Haha... earn your grade :p

akniss
November 18th, 2007, 04:20 AM
please send anser less than one hour.
That's my favorite part! #-o

slimdog360
November 18th, 2007, 11:08 AM
I have an answer


DO YOUR OWN HOMEWORK

jatos
November 19th, 2007, 04:30 PM
If you going to try this trick, leasst make sure it doesn't sound like its for homework...