Subj : Re: malloc and free To : borland.public.cpp.borlandcpp From : maeder Date : Mon Jul 12 2004 09:31 pm "Alistair" writes: > char * memused = (char *)malloc(80); //allocate 80 bytes > memset(memused, '\0', 80); > strcpy(memused, "TEST"); > > How do i find out how many bytes memused has if I dont remember the value > 80? > strlen returns 4, which is correct, but I want the amount of memory > allocated in the first place. In addition to Ed Mulroy's post: In almost all cases, it is better to use a container object instead of a dynamically allocated array. In this case, that would be std::string memused(' ',80); memused = "TEST"; [Depending on the compiler and library version you are using, you have to or must not write the std:: prefix".] This would not only allow you to query the allocated size using the capacity() member function, but also automagically deallocate that memory once memused isn't used any longer. .