Im currently stuck on some weird issues im not understanding.
I have compiled my program for unix with gcc and now im trying to run it, what happens is that
the program initializes a socket-io-service and crashes instantly because it tries to allocate memory with the boost pool.
Im trying to create a new instance of foo..
for (int i = 0; i <= 32; i++)
{
foo* bar = new foo();
}
This is what happens when new is called:
void * operator new (size_t size)
{
(void)size;
return (void *)(mypool.malloc());
}
If i use malloc(size_t) instead of m_pool.malloc() everything starts up fine..
Things i used:
GCC v11
Boost 1.59
Boost 1.65
Boost 1.81
CentOs 7
Ubuntu 22.04
I dont understand what is happening here, is it maybe some issue with x32/x64?
Or could it be the compiler?
I hope you guys can help, if needed more information please ask
I tried different systems, different boost version, i also created a simple program and manually tried the pool.. it worked
2
Answers
I found the issue!
The program uses a library which runs the critical code, and what happened was that this code:
Got executed in the constructor from a class which is a singleton.
The singleton was declared like this in the header:
So as the program was starting the frist thing that happenend was creating an instance of the singleton from the library.. (see the startup below..)
So my thought was: A memory allocation can't happen if there is no main-thread yet.. please correct me if im wrong here because im not sure!
And then i changed the singleton to this:
And it worked!
I think that the instance was created immediatly because it was directly in the header and that the current gcc-compiler handles it different then in older versions..
Note that i migrated that project from C++98. Now it runs fine and i can finally use the benefits of newer C++ versions!
gcc44 "centos 6.10" it works outside of the function like
gcc48 and above? "centos 7.9 core" gcc 4.8.5
some reason wants it inside the function.
Thank you for this <3 saved me a headache compiling haha