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-23 2:21

>>37
man vim

Name: Anonymous 2008-10-23 4:01

Better to use ssize_t just in case memory ever gets that large.
no.
http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/types.h.html
size_t
    Used for sizes of objects.
ssize_t
    Used for a count of bytes or an error indication.

size_t is the correct type to use in this case, since it won't be used to store an error indication.
also, malloc() and realloc() take size_t arguments, not ssize_t:
http://www.opengroup.org/onlinepubs/000095399/functions/malloc.html
http://www.opengroup.org/onlinepubs/000095399/functions/realloc.html

>>39-40
man ed

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