This class uses reference counting to help manage memory areas. The memory may be allocated with the C++ " new " operator, SysV shared memory or mmap. The class keeps track of who owns the memory, who is responsible for deleting it when no longer needed and how many references there are to the memory area. When there are no more references, we can safely detach a shared memory area and if we are the "owner", delete it. Constructor arguments and flags determine whether shared memory, mmap or normal (unshared) memory is allocated or whether existing shared memory is used. The state can be changed at any time, i.e.: shared memory can be changed to unshared and unshared to shared.
The following example allocates 10000 bytes of sysV shared memory:
Mem m(10000, 1); char* p = (char*)m.ptr();
This example uses mmap to map a file to memory:
Mem m(filename); char* p = (char*)m.ptr();
See the man page Mem(3) for details on the various constructors and methods.
Please send questions or comments to abrighto@eso.org.
Copyright © 1998 ESO - European Southern Observatory