is shared memory expandable in memory size?
hiho@ll
i try to write a prog which stores statistics and another prog needs to read it i don't use sockets, because they are slower than sharedmem and for this special purpose its a bit complicated so i though about a structure which holds a vector, the vector then has also vectors as child elements (so i get something like a Database Table) so i can store data using x and y coordinates my question: will it work? i'm already working on it, but i'm not really finished and i just wanted to know if it's the right way? will it work, if i store the statistics in the vectors, depending on how much statistics i get or does shared memory not work with expandable memory space? first i thought it will be a problem, because shared memory is something like special kernel memory (afaik), so it has it's limits on the other hand i think, there is only the vector itself stored in the shared memory. if i add something to the vector, the vector allocates memory and stores it. so i think there will only be the vector object in the shared memory and the data i inserted will be somewhere allocated by the vector? |
Erm. I'm not sure what expandable means in this question.
you can mmap/shmget a big chunk of memory and use it. Do you mean dynamically expand shared memory? |
If I understand the question correctly the OP is storing a struct/class containing pointers/references to seprately allocated data, and he/she is wondering how to make sure those referenced data is available to other processes through the shared memory.
I don't know the answer though... |
yep
i just need memory, which is read/writeable by many applications but the amount of data is dynamic sometimes more sometimes less as i can estimate the prog it will need less memory in the beginning and during the first few minutes it will need more memory which will be very constant at some time but it should be possible to allocate and expand the needed memory |
Just allocate one shared-memory segment initially, and allocate more segments as needed. Programs only need to find this first segment to "rendezvous" with each other.
Devise your own logic, e.g. a set of free-lists, for suballocating storage as required... perhaps ... Code:
(struct whizboz *) alloc_whizboz() { A pointer may point from one segment to another segment without restriction. If you have data-structures which are "logically" contiguous and flat, design them (e.g. using C++ classes) so that they "physically" do not have to be. Thus you never have to "resize" anything. You may need to build trees or hash-tables or whatnot to enable you to efficiently locate a particular entry in this now-sparse data structure... |
All times are GMT -5. The time now is 05:32 PM. |