Subj : Re: malloc and free To : borland.public.cpp.borlandcpp From : Alistair Date : Tue Jul 13 2004 09:40 pm Thank you for all the input but the allocation of memory isnt just for strings, its for anything and also the size of allocation isnt set, it depends on what is going on also, there are many allocations of chucks before its all freed (at different points). _msize is good enough for what I need it for and I dont plan for backward compatability. The only other method I would use is remember the data by passed the data as part of a structure, e.g. struct memobj { void *data; int size; }; then pass this around instead of the void *. I do this now, but I wanted to find out if I could find out the size of the memory allocation without remembering it. I have a way of doing this now, even if its not standard. I wont replace my remembering object, I will just add this as additional functionality if I need it at some point. Cheers Alistair "Jan Vernimmen" wrote in message news:40f3d652@newsgroups.borland.com... > Hallo, > > Is not the best thing you can do make an include file with all your constant > values (also CM_xxx and WM_xxx) for this project, something like in this case: > . > . > #define LEN_MEMUSED 80 > . > . > > char * memused = (char *)malloc(LEN_MEMUSED); //allocate 80 bytes > memset(memused, '\0', LEN_MEMUSED ); > . > . > and so on > Greetings, > Jan > > > > Alistair wrote: > > 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. > > > > Does anyone know?! > > > > Cheers > > > > Alistair > > > > > .