Public Group

# using stl with memory managed code

This topic is 4165 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm using an engine which has its own memory manager. STL won't compile under the engine's memory manager, so I can't really have STL includes in header files, short of having a global include file which every single source and header file includes first. I know that using forward declarations the compiler doesn't have size information. So, is there a workaround to accomplish something like this?
template <> class std::vector;

class A {
std::vector<int> data;
}

##### Share on other sites
Why not include the memory management headers after you include the SC++L headers? That should eliminate the compiler issues, unless they're particularly complex ones. What exactly causes the failure to compile?

##### Share on other sites
there are very complex header chains that are not my code to refactor. I don't know if they even can be refactored.

if I include <vector> in my header, then another header file includes my header (but not at the very top), the latter header will not compile. Its very easy to get chains that are not terribly complicated that have no solution order that compiles. I wouldn't want to waste my time and sacrifice my organization to find such a sol'n anyway.

It's either a global include-me-first include file with every single used STL header (and any other external libraries that I don't want memory managed...), or forward declarations of some sort. I don't like the idea of global headers.

##### Share on other sites
Still doesn't answer my question, what are the compilation errors? There are still potential trivial solutions to the problem.

Lots of memory management tools use macros to replace new and delete, for example; that can cause errors. This can be avoided by including simple headers that undefine and redefine the macros, using those to bracket the SC++L headers.

##### Share on other sites
1>c:\program files\microsoft visual studio 8\vc\include\crtdbg.h(1118) : error C2653: 'MemoryMgr' : is not a class or namespace name1>c:\program files\microsoft visual studio 8\vc\include\crtdbg.h(1118) : error C2833: 'operator SetCurrentLocation' is not a recognized operator or type1>c:\program files\microsoft visual studio 8\vc\include\crtdbg.h(1118) : error C2059: syntax error : 'newline'1>c:\program files\microsoft visual studio 8\vc\include\crtdbg.h(1118) : error C2059: syntax error : 'new'1>c:\program files\microsoft visual studio 8\vc\include\crtdbg.h(1120) : error C2653: 'MemoryMgr' : is not a class or namespace name1>c:\program files\microsoft visual studio 8\vc\include\crtdbg.h(1120) : error C2833: 'operator SetCurrentLocation' is not a recognized operator or type1>c:\program files\microsoft visual studio 8\vc\include\crtdbg.h(1120) : error C2059: syntax error : 'newline'1>c:\program files\microsoft visual studio 8\vc\include\crtdbg.h(1120) : error C2059: syntax error : 'new'1>c:\program files\microsoft visual studio 8\vc\include\crtdbg.h(1127) : error C2653: 'MemoryMgr' : is not a class or namespace name1>c:\program files\microsoft visual studio 8\vc\include\crtdbg.h(1127) : error C2833: 'operator SetCurrentLocation' is not a recognized operator or type1>c:\program files\microsoft visual studio 8\vc\include\crtdbg.h(1127) : error C2059: syntax error : 'newline'1>c:\program files\microsoft visual studio 8\vc\include\crtdbg.h(1127) : error C2059: syntax error : 'new'

The engine I am using has no such "unclusion" headers, that I am aware of.

##### Share on other sites
Perhaps you can make some. Offhand (and I don't have a copy to look at right now), crtdbg.h doesn't have a MemoryMgr class, so it's not a class conflict in any way...

It sounds like there is some macro you've got that is being replaced to reference MemoryMgr, et cetera, and that macro is in scope before you include external headers (it really, really should not be, its usually a huge pain to accurately track the memory used by external code and often not worth it).

See if your memory manager employs macros in any way. If it does, you can create disabling headers yourself. Otherwise I'd probably need more information about how the manager works and looks like to provide solid alternative solutions.

##### Share on other sites
Yeah, that's basically my understanding. I'm really hoping to not have to modify the engine / add headers / do whatever at a low level. I've brought this issue to their community, hopefully they have a solution.

##### Share on other sites
aaand unfortunately its not using macros very heavily.

My peer got it to compile, and now we have vector internally memory managed by our engine. It works, but is sketchy as hell and I for one am not comfortable with this game engine managing external code.

Can anyone comment on using STL or other std:: stuff with a custom new operator?

Also, if a mod can move this to general programming, because this is no longer a beginner's discussion...

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013710
×