STL, std::allocator and memory mapped files 
Author Message
 STL, std::allocator and memory mapped files

I want to use memory mapped files to store my application specific
data. I will be needing lists and maybe some other STL classes. Since
memory mapped files are no more than a range of ordinary addresses in
user space, I thought I might use STL lists instead of inventing my
own but one big problem arises. Memory mapped file can be mapped to
different start address each time it's created so list's pointers
should actually be offsets to the beginning of the file and not actual
pointers. Offsets are easily translated into actual pointers by adding
the start address of a memory mapped file.

Has anybody ever done anything like this? I am not an expert in STL so
I'm seeking help. I thought that changing std::allocator class will do
the trick. I have looked at the source of std::allocator and std::list
and haven't found a way to do what I want. Am I just missing something
or is it really impossible?

Thanks.
--
Alex.
---------------------------------------------
My reply address is altered. Remove STOPSPAM.



Thu, 13 Dec 2001 03:00:00 GMT  
 STL, std::allocator and memory mapped files

Quote:

>I want to use memory mapped files to store my application specific
>data. I will be needing lists and maybe some other STL classes. Since
>memory mapped files are no more than a range of ordinary addresses in
>user space, I thought I might use STL lists instead of inventing my
>own but one big problem arises. Memory mapped file can be mapped to
>different start address each time it's created so list's pointers
>should actually be offsets to the beginning of the file and not actual
>pointers. Offsets are easily translated into actual pointers by adding
>the start address of a memory mapped file.

>Has anybody ever done anything like this? I am not an expert in STL so
>I'm seeking help. I thought that changing std::allocator class will do
>the trick. I have looked at the source of std::allocator and std::list
>and haven't found a way to do what I want. Am I just missing something
>or is it really impossible?

std::list, std::map, etc. use pointers internally. Unless you can guarantee
the shared memory is mapped to the same logical address in all apps using a
shared STL container, it won't work. If you can guarantee this, don't forget
that the list, map, or whatever must itself reside in the shared memory, and
any memory dynamically allocated by the container's values must reside in
the shared memory as well. For example, suppose you arrange for a std::list
object to reside in a shared memory section named X, and you give it an
allocator that allocates from X. If the list contains strings, the strings
must also obtain their dynamic storage from X; the list's allocator
parameter is concerned only with allocations made by the list, not
allocations made by objects stored in the list.

--
Doug Harrison

Visual C++ MVP



Fri, 14 Dec 2001 03:00:00 GMT  
 STL, std::allocator and memory mapped files

Quote:

>std::list, std::map, etc. use pointers internally. Unless you can guarantee
>the shared memory is mapped to the same logical address in all apps using a
>shared STL container, it won't work. If you can guarantee this, don't forget
>that the list, map, or whatever must itself reside in the shared memory, and
>any memory dynamically allocated by the container's values must reside in
>the shared memory as well. For example, suppose you arrange for a std::list
>object to reside in a shared memory section named X, and you give it an
>allocator that allocates from X. If the list contains strings, the strings
>must also obtain their dynamic storage from X; the list's allocator
>parameter is concerned only with allocations made by the list, not
>allocations made by objects stored in the list.

Thanks. After I posted the question I have given it even more thought
and I've found out that it would be very complicated if at all
possible. I thought that deriving from std::allocator would solve much
of the problem but now it doesn't seem so.

Anyway, I think I will drop this method and try something else.

Thanks for the effort, though.

--
Alex.
---------------------------------------------
My reply address is altered. Remove STOPSPAM.



Sat, 15 Dec 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. STL custom allocator using memory mapped file

2. STL map and probable allocator problem

3. SGI STL STLPort deque memory leak (not related to optimized allocator)

4. Memory-mapped files - pros and cons of mapping view on whole file

5. custom container allocators and custom memory allocators

6. Exporting STL containers (specifically std::map) from DLL?

7. URGENT: STL std::map<ULONG, CEvent>

8. Memory leak? (std::map, VC7)

9. IPC: Shared memory via dll vs memory map file

10. copying CObject-derived-classes to shared memory (created using Memory-Mapped file)

11. Passing std::set and std::map objects between 2 dlls

12. STL and memory mapping

 

 
Powered by phpBB® Forum Software