#include "k_alloctable.h"
std::map< void*, size_t > entries;
void Log( void* p, size_t s )
{
std::map< void*, size_t >::iterator i;
if ( p == NULL )
return;
i = entries.find( p ); // *
if ( entries.end() == i )
return;
//entries[ p ] = s;
}
This me being dumb?
I can't seem to get this work.
The background is that i'm experimenting with overloading new and delete and have my own versions. I want to track every byte that is allocated and deallocated. So i have written some code in a CPP file with a header, not a class, and i'm getting an exception.
I get an exception on the line marked with an asterisk. The problem is that the entries map is not initialised properly. I'm confused, i could have been sure that is woulf have been initialised like this. Oh and before anyone suggests it i can't put on the heap because the new operator brings me here again.
Any ideas.
ace
entries is not a pointer, so you should be using entries.find and entries.end
but this shouldn't compile at all, so I don't see why you're getting exceptions.
but this shouldn't compile at all, so I don't see why you're getting exceptions.
I may sound stupid, but... Isn't Map using new all over the place to create its nodes? So, effectively, it may be running an infinite loop and overloading the stack?
EDIT
rick_appleton: damn right, why didn't I notice it :)
EDIT
rick_appleton: damn right, why didn't I notice it :)
Yeah sorry i forgot to change the -> to . It may be the case that map stores by value on the heap.
In which case i could simply have an array of structs and realloc it to resize it.
Does this make sense?
ace
In which case i could simply have an array of structs and realloc it to resize it.
Does this make sense?
ace
Some part of the C++ runtime library is using operator new and running before initialization of the global variable entries is actually taking place.
Quote:Original post by ace_lovegrove
Yeah sorry i forgot to change the -> to . It may be the case that map stores by value on the heap.
In which case i could simply have an array of structs and realloc it to resize it.
Does this make sense?
ace
Since you want to allocate memory yourself, yeah, it does make sense. I don't think malloc will be subject to the problem you,re describing.
structure * ptr = malloc(sizeof(structure) * NUM_STRUCTURE);
...
realloc()
...
free()
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement