From: Joerg \Sharky-X\ R. <as...@gm...> - 1999-12-30 03:41:55
|
Just adding the allocated bytes isn't enough. Sometimes it happens in some programs, that the allocated memory is freed again after usage ;). But if you wrap free() you don't know the size of the block which is freed so you need to create a list and store the pointers you allocate along with the size. When calling free() it has to search trough the list for the pointer and subtract the according size from mem_used. And when you have done this, you can also easily check if you try to free memory block you haven't allocated before and if you add some more checks you have a nice memory debugging library before you notice it :). So, if you have finished your debug lib for MSVC, give it to me please ;) Jörg ----- Original Message ----- From: Clarke, Andy D (CALNZAS) <And...@co...> To: <al...@ca...> Sent: Thursday, December 30, 1999 12:35 AM Subject: RE: [AL] See used RAM with MSVC++ > The trouble with that (perfectly sound) solution is that it won't track > usage by third-party libraries (ie: allegro), unless you compile the source > right into your program, so that they may use the wrapped malloc/free. > > This may or may not be what you want. > > If you are using a debug build, the following may work. I haven't tested it > though, so there are no guarantees the figure will be accurate. > > Allocate some memory at the start of your program. > Whenever you wish to find out how much you have used: > mem_used=(int )malloc(0)-(int )initial_alloc; > > Now, some caveats. > This figure includes all of the debug headers and padding. This however, > shouldn't be too significant. > This method also assumes that the debug heap is linear (and I see no reason > why it wouldn't be). > If you don't like leaving zero-sized mallocs all over the place, assign them > to a variable then free them. > > I'd be interested to know if this works. > > Cheers > Andy Clarke > > Windows NT: Neurotic Tendencies. > > -----Original Message----- > From: Michael Bourgeous [mailto:nit...@so...] > Sent: Thursday, December 30, 1999 12:18 PM > To: al...@ca... > Subject: Re: [AL] See used RAM with MSVC++ > > Thomas wrote: > > > > Does anyone know how to see how much RAM > > my program is using? > > I'm programming in MSVC++ 5.0 > > You could write wrappers for malloc and free (or new and delete in C++) > to keep a running total of the number of bytes allocated - this would > give an approximation. > |