This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

std::map allocations questions


Hi,

sorry to bother you here,

I wanted to create a memory checker for my programs. I tried to used
std::map for this.
So I do something like this (I don't like to send code like this, the
first time, but I hope this would help...)

[CODE] // just for conveniency

struct MemEntry
{
	typedef unsigned long long addr_type;
	
	addr_type start_address;
	size_t 	size;
	addr_type end_address;
};

struct MemMap
{
	public:
	
	typedef map<MemEntry::addr_type, MemEntry> _MemMap;
	
	private:
	
	_MemMap memory_map;
	
	public:
		
	MemMap()
	{
	}
		
	void
	Record (const MemEntry& entry)
	{
		memory_map.insert (pair<MemEntry::addr_type, MemEntry> (entry.start_address, entry));
		//memory_map[entry.start_address] = entry;
	}
};

[/CODE] // idem

...

With the appropriate overloading of new function.

When I try to record a new allocation inside the new function, it appears that
the recording is happening thousands of times until the program crashes by
segfault.

So I suspected std::map insertions to call for new by itself.

Is it a normal thing ? Do you unrecommand to use std::map for memory
allocation checkings ? Should I develop my own map ? Maybe I've done
something wrong ?

The "recursive" new_allocation happens when calling the Record member
function.

I really wasn't expected such a behavior.

Really hope you could help me. If not, then I'll stuck with thinking that
I should really not use std::map for this, and try to do it another way.

Thanks in advance,

best regards.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]