LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

Rep: Reputation: 30
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?
 
Old 08-12-2005, 10:33 AM   #2
jim mcnamara
Member
 
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
Hko
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
Thinking
Member
 
Registered: Oct 2003
Posts: 249

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

Rep: Reputation: 3944Reputation: 3944Reputation: 3944Reputation: 3944Reputation: 3944Reputation: 3944Reputation: 3944Reputation: 3944Reputation: 3944Reputation: 3944Reputation: 3944
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...

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


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:12 AM.

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