Fixing the Size of a Map in Shared Memory

  • Context: C/C++ 
  • Thread starter Thread starter FrostScYthe
  • Start date Start date
  • Tags Tags
    Map Memory
Click For Summary
SUMMARY

The discussion focuses on the challenges of allocating a fixed size for a map in shared memory using C++. Specifically, the user inquires about defining a fixed-size map similar to a fixed-size array, illustrated by the struct Table containing a map. Warren clarifies that while a fixed-size array can be easily defined, a map does not guarantee contiguous memory allocation, complicating its use in shared memory scenarios. The conclusion emphasizes that sharing a map object in shared memory may not achieve the intended results due to potential non-contiguous data storage.

PREREQUISITES
  • Understanding of C++ data structures, specifically maps and arrays.
  • Knowledge of shared memory concepts in inter-process communication.
  • Familiarity with memory allocation and management in C++.
  • Experience with struct definitions in C++.
NEXT STEPS
  • Research fixed-size data structures in C++, such as std::array and std::vector with reserved capacity.
  • Explore shared memory implementation techniques using POSIX or System V IPC in C++.
  • Learn about memory layout and allocation strategies for complex data types in C++.
  • Investigate alternatives to maps for fixed-size data storage, such as hash tables or custom data structures.
USEFUL FOR

Software developers, particularly those working with C++ and inter-process communication, as well as systems programmers dealing with shared memory management.

FrostScYthe
Messages
80
Reaction score
0
Hi, I'm wondering how to give a map a fixed size like you can give an array a fixed size by just "byte data[SIZE*DATASIZE]".. or if it's possible anybody know..

struct Table {
map<int, int> table; //
};

struct Table *flightChart;

The reason I have to give this a fixed size, is because I have to map this in shared memory :\, so that another process may access it, or is it possible to pass this structure to another process without shared memory :\
 
Technology news on Phys.org
Even if it were fixed size, sharing your map object in shared memory might not accomplish what you want to do anyway. There's no guarantee that the map object store its data within a single contiguous block of memory -- it may store data in blocks all over the heap.

- Warren
 

Similar threads

  • · Replies 17 ·
Replies
17
Views
4K
  • · Replies 8 ·
Replies
8
Views
5K
  • · Replies 10 ·
Replies
10
Views
7K
Replies
20
Views
2K
  • · Replies 26 ·
Replies
26
Views
4K
Replies
5
Views
2K
  • · Replies 15 ·
Replies
15
Views
7K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K