Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-12-2005, 02:08 AM   #1
Registered: Oct 2003
Posts: 249

Rep: Reputation: 30
is shared memory expandable in memory size?


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?
Old 08-12-2005, 10:33 AM   #2
jim mcnamara
Registered: May 2002
Posts: 964

Rep: Reputation: 36
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?
Old 08-13-2005, 05:07 AM   #3
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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...
Old 08-13-2005, 06:41 AM   #4
Registered: Oct 2003
Posts: 249

Original Poster
Rep: Reputation: 30
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
Old 08-16-2005, 09:57 AM   #5
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,708
Blog Entries: 4

Rep: Reputation: 3949Reputation: 3949Reputation: 3949Reputation: 3949Reputation: 3949Reputation: 3949Reputation: 3949Reputation: 3949Reputation: 3949Reputation: 3949Reputation: 3949
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 ...
(struct whizboz *) alloc_whizboz() {
struct whizboz *result = remove_from_freelist(global->whizbozlist);
if (!result) result = carve_out_storage(sizeof(struct whizboz));
if (!result) {
  result = carve_out_storage(sizeof(struct whizboz));
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...

Last edited by sundialsvcs; 08-16-2005 at 10:04 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
tool to detect number of memory slots, memory module type, speed, and size stefanwolf Linux - Hardware 8 04-22-2013 09:48 AM
Shared memory size limit? nodger Programming 1 03-16-2005 08:28 AM
c + shared memory dilberim82 Programming 3 03-07-2005 07:49 PM
shared memory blackzone Programming 1 10-14-2004 11:52 AM
Help!?! RH 8 Memory Mapping -High Memory-Virtural Memory issues.. Merlin53 Linux - Hardware 2 06-18-2003 04:48 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:19 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration