LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   is shared memory expandable in memory size? (https://www.linuxquestions.org/questions/programming-9/is-shared-memory-expandable-in-memory-size-352427/)

Thinking 08-12-2005 02:08 AM

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?

jim mcnamara 08-12-2005 10:33 AM

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?

Hko 08-13-2005 05:07 AM

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...

Thinking 08-13-2005 06:41 AM

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

sundialsvcs 08-16-2005 09:57 AM

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() {
obtain_memory_mutex();
struct whizboz *result = remove_from_freelist(global->whizbozlist);
if (!result) result = carve_out_storage(sizeof(struct whizboz));
if (!result) {
  get_another_segment();
  result = carve_out_storage(sizeof(struct whizboz));
}
release_memory_mutex();
return result;
}

Both the size of the initial segment and the (default) size of subsequent segments should be program options.

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.