Message-ID: <384735753.961926689108.JavaMail.root@web443-mc.mail.com> Date: Sun, 25 Jun 2000 05:51:28 -0400 (EDT) From: Martin Nilsson To: djgpp AT delorie DOT com Subject: Unstandard mallocation needed Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: mail.com X-Originating-IP: 212.209.5.32 Reply-To: djgpp AT delorie DOT com Some memory allocation questions: QUESTION I The comp.lang.c FAQ says 7.27 Q: So can I query the malloc package to find out how big an allocated block is? A: Unfortunately, there is no standard or portable way. but I would like to do it anyway, with DJGPP. None of the memory allocation routines listed in info.exe seem to fit. Does somebody know how to do it? It would be extra nice if the solution was somwhat portable to the GNU GCC compiler. QUESTION II You can use realloc to free the last n bytes of a memory area, like this: byte *p = malloc(100); . . . p = realloc(p, 50); /* saving the contents of bytes 0..49, freeing bytes 50..99 */ thus doing a nifty "slicing" operation without having to copy anything. It would be nice to also be able to do the "opposite" operation, i e freeing the *first* n bytes, like this: byte *p = malloc(100); . . . p = free_the_first_n_bytes(p, 35); /* p now is old p + 35; bytes 0..34 are freed */ Thanks /Martin Nilsson ______________________________________________ FREE Personalized Email at Mail.com Sign up at http://www.mail.com/?sr=signup