mardi 27 novembre 2018

boost managed shared memory construction ends up with "bus error"

I have a code that is going to create a big segment on managed shared memory using c++ boost (about 2 Gigs). And if we don't have enough memory on the machine, it will receive bus error.

Actually, the error happens when I try to write on shared memory with use of construct function. When I create the segment, it doesn't receive any error. I've already check my segment's size and free size and they all would be showing values that if there was enough memory to allocate! (get_size returns 2000000000!). even if the machine has less than that!

I know that the OS makes the program think that there exists enough memory, but I have to run the code on different machines and it must work on all of them. I mean, it MUST NOT crash even if there doesn't exist enough memory and we should have a good exception to be thrown out in this case. No mater that there exists enough memory or not. And there must be a way to find this out programmatically.

So, I was wondering is there any way to understand whatever requesting memory exists or not "USING BOOST"?

Here is what I want (Or at least have in mind!)

// consider that we are going to create a shared memory segment with 2G size in a machine that only has 1G of RAM
boost::interprocess::managed_shared_memory segment(open_or_create, "name", 2000000000);
if (real_allocated_memory < actual_need)
    throw std::overflow_error("Not enough memory");
segment.find_or_construct(a huge object); // here is where I receive the error

Aucun commentaire:

Enregistrer un commentaire