Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#4522 closed Bugs (invalid)

allocation problem after grow

Reported by: razzik@… Owned by: Ion Gaztañaga
Milestone: Boost 1.44.0 Component: interprocess
Version: Boost 1.43.0 Severity: Showstopper
Keywords: interprocess shared_memory ipc grow allocation Cc: razzik@…

Description

Hi,

the allocation mechanism damaged by call grow() function...

This part work fine:

/* Create SM - Size 100K*/
managed_shared_memory shm(create_only, "MySM", 100*1024);
/* SM full size - 100K*/
int fullSMSize = shm.get_size();
/* SM mem size - 100K - sizeof(SM Header)*/
int memSMSize = shm.get_free_memory;
/* alloc 64K in SM (64K<100K)*/
void* ptr = shm.allocate(64*1024);

By adding grow function the allocate function throws exception:

/* Create SM - Size 100K*/
managed_shared_memory shm(create_only, "MySM", 100*1024);
/* Grow SM By 28K*/
managed_shared_memory::grow("MySM",28*1024);
/* SM full size - 128K*/
int fullSMSize = shm.get_size();
/* SM mem size - 128K - sizeof(SM Header)*/
int memSMSize = shm.get_free_memory;
/* alloc 64K in SM (64K<128K)*/
void* ptr = shm.allocate(64*1024);

Thanks, Raz

Change History (3)

comment:1 by Ion Gaztañaga, 12 years ago

Resolution: invalid
Status: newclosed

From the help:

"Boost.Interprocess offers off-line segment growing. What does this mean? That the segment can be grown if no process has mapped the managed segment. If the application can find a moment where no process is attached it can grow or shrink to fit the managed segment."

So you must unmap, grow and remap it again:

/* Create SM - Size 100K*/<br>
{
managed_shared_memory shm(create_only, "MySM", 100*1024);
}
//Unmapped here

/* Grow SM By 28K*/
managed_shared_memory::grow("MySM",28*1024);

//Remap it
managed_shared_memory shm(open_only, "MySM");

/* SM full size - 128K*/
int fullSMSize = shm.get_size();
/* SM mem size - 128K - sizeof(SM Header)*/
int memSMSize = shm.get_free_memory();
/* alloc 64K in SM (64K<128K)*/
void* ptr = shm.allocate(64*1024);

comment:2 by Raz <razzik@…>, 12 years ago

Thanks igaztanaga!'''

You are right, in general the growing should be when the SM is unmapped.

Basically, I need shared memory with Fix memory size. But, I don't know the memory size used by Shared Memory mechanism. So, I use grow after using get_free_memory() function.

How can I set in the constructor of the managed_shared_memory the required memory without knowing the SM mechanism size?

Thanks again for your assistance,
Raz

P.S. General question: If the SM based on file I can't call shrink_to_fit() when the SM is mapped, But what about grow?

in reply to:  1 comment:3 by Raz M <razzik@…>, 12 years ago

Thanks igaztanaga!'''

You are right, in general the growing should be when the SM is unmapped.

Basically, I need shared memory with Fix memory size. But, I don't know the memory size used by Shared Memory mechanism. So, I use grow after using get_free_memory() function.

How can I set in the constructor of the managed_shared_memory the required memory without knowing the SM mechanism size?

Thanks again for your assistance,
Raz

P.S.
General question:
If the SM based on file I can't call shrink_to_fit() when the SM is mapped, But what about grow?

Replying to igaztanaga:

From the help:

"Boost.Interprocess offers off-line segment growing. What does this mean? That the segment can be grown if no process has mapped the managed segment. If the application can find a moment where no process is attached it can grow or shrink to fit the managed segment."

So you must unmap, grow and remap it again:

/* Create SM - Size 100K*/<br>
{
managed_shared_memory shm(create_only, "MySM", 100*1024);
}
//Unmapped here

/* Grow SM By 28K*/
managed_shared_memory::grow("MySM",28*1024);

//Remap it
managed_shared_memory shm(open_only, "MySM");

/* SM full size - 128K*/
int fullSMSize = shm.get_size();
/* SM mem size - 128K - sizeof(SM Header)*/
int memSMSize = shm.get_free_memory();
/* alloc 64K in SM (64K<128K)*/
void* ptr = shm.allocate(64*1024);
Note: See TracTickets for help on using tickets.