home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16869 < prev    next >
Encoding:
Text File  |  1992-11-20  |  932 b   |  41 lines

  1. Path: sparky!uunet!olivea!charnel!sifon!vugranam
  2. From: vugranam@pike.ee.mcgill.ca (Vugranam Chakravarthy Sreedhar)
  3. Newsgroups: comp.lang.c
  4. Subject: Memory Info.
  5. Message-ID: <1992Nov20.130913.20148@sifon.cc.mcgill.ca>
  6. Date: 20 Nov 92 13:09:13 GMT
  7. Sender: news@sifon.cc.mcgill.ca
  8. Organization: McGill University - VLSI Laboratory, Montreal, CANADA.
  9. Lines: 29
  10. Nntp-Posting-Host: kirk.ee.mcgill.ca
  11.  
  12.  
  13. Given a pointer to a object that has been previously allocated using
  14. one of the allocation routine, how can I get the
  15. size of the object.
  16.  
  17. For example,
  18.  
  19. char *c;
  20. long  x ; 
  21.  
  22.  c = (char *) malloc (100) ;
  23.     .
  24.     .
  25.     .
  26.  
  27. x = mem_size(c) ;   /* x is block size of c, which in this case is 100 */
  28.  
  29.  
  30. I want to use this to keep track of memory statistics. Now what I do is
  31. to pass the size to my memory routines. Like
  32.  
  33. int *mymalloc(size) ;  /* this is easy */
  34.  
  35. int myfree(char *, long size)   /* I don't like this !!*/
  36.  
  37. Thanks
  38.  
  39.  
  40. Sreedhar
  41.