Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

allocating memory

Name: Anonymous 2008-10-21 23:16

have this pointer
Char *ptr
i allocate memory as
ptr = (char *) malloc (sizeof(char) * 100);
say later on in the program i may or may not need to store more characters so i'll use realloc to assign more memory. How can i find out how much memory is currently assigned to ptr so i cant find if i need to resize it or not.

Name: Anonymous 2008-10-22 11:49

>>7
Yes. The C way is great for C programs, and the C++ way is great for C++ programs. However, since malloc() is a C function and should almost never be used in a C++ program, it's better to assume C semantics and state that the cast is not required.

When you think about it, casts are never really required for a pointer, because all pointers take the same amount of memory, but allowing conversions to and from void*  pointers without error or warning makes things easier.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List