Memory allocation in libC

Memory allocation in libC

Postby amit.sahrawat » Sat Sep 12, 2009 8:22 am

let's say we have allocated a memory of 100 bytes.
char *ptr = (char*) malloc(sizeof(char)* 100);

Now suppose, I write more than 100 bytes at this location.
strcpy(ptr, <Buffer greater than 100bytes say 120 bytes>);
or
memcpy(ptr,'6',120);

Why do u observe a crash.. What is the reason behind this? How can this be be explained.

Or suppose we have to write our own Memory Allocation library what data strucutres are to be used and how should we start with this?

-- Amit Sahrawat
amit.sahrawat
 
Posts: 4
Joined: Tue Sep 01, 2009 3:41 pm

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest



cron