this is the simple algoritm jst n case u r interested....
At the very beginning a char array of size 50000 is declared(50000 bytes). All the memory allocations are done in this area and no local variables are allowed. In this array the last 10 bytes are used to store the variables that are being used while implementing these methods. This area is used for this purpose only.
Memory is used as blocks in these two methods. Each block has one byte to keep track the status of the block as to the particular block is free or not(-2 is used to indicate that the block is free and -1 is used to indicate that it is not free), at most five bytes to store the size of the block an one byte which is null which is used when reading the size of the block using atoi()
At the very first time when the array is not used the first bit of the array is made -2 to indicate that the array is free. Then in the next 5 bytes we put the size of the available block which is (array size-10-7).
When NewMalloc is called it searches for a block which has the size of user’s required size or for a block which is greater than that size. Once the block is found if it’s free it writes -1 on the first byte to indicate that it’s not free. If the block is exactly the size of what the user wants NewMalloc returns a pointer to the assigned block. If the block is greater than the users size it checks if (size of the block-user size)>7. If the above condition is false the remaining bytes are attached to the block which is given to the user and the pointer is returned as above. However a bigger block is given to the user in this case. This is done as 7 bytes are use as a header in this method. If a new block is to be created the size of it should be greater than 7. If the remaining size is greater than 7 the user required block is given to the user and the remaining part is treated as a new block which means that it too will have a header area to indicate the status of the block and the size. The size of the new block is (size of the block-user size-7).
If by any chance NewMalloc couldn’t find a block which is free and which can be used it will return 0.
When a block is freed by the user this method simply puts -2 to the 1st byte of the header area of the block to indicate that the block is free.
Afterwards if there are any free blocks beside it, it will merge these blocks and will make it one free block and will update the header area as needed. Because of this there want be any free blocks next to another free block. This is the algorithm used in this method
thankyou very much for ur help.i realy appreciate dat.