473,381 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 software developers and data experts.

shared memory and multidimensional arrays...

Ok...so, I have been outside of the C world for a _very_ long
time...but not so long as to remember how to do multidimensional
arrays. So, let me state that I know how to malloc pointers to
pointers and then malloc my data space. This question is NOT about

I need to keep a dynamically sized (a result of command line options)
matrix in a shared memory segment created via shmget and attached via
shmat. My first instinct was to do what I would do if I were using
malloc. However, the docs for shm.h tell me that it is not safe to
share my pointers, as the shared memory may be attached at a different
point on different processes. So, my question is, whether or not
there is a "standard", or at least common, way of doing shared
multidimensional arrays. I could always "simulate" a multidimensional
array in a single dim. array, but that seems less than ideal. Any

Feb 19 '08 #1
2 4458
That should have said..."not so long as to _fail_ to remember how to
do multidimensional arrays."

my bad... ;)

Feb 19 '08 #2
point on different processes. So, my question is, whether or not
there is a "standard", or at least common, way of doing shared
multidimensional arrays. I could always "simulate" a multidimensional
array in a single dim. array, but that seems less than ideal. Any
You do not have many options here. You'd have better luck in

The shared memory segment is one big chunk of memory mapped to your
current address space, it does not carry any more information than
that. Your code will be the one responsible to make this big piece of
memory meaningful.
As you said, pointers cannot be shared (since they are tied to each
process address space and hence likely to be different for every
process) as such, each process that maps this shared memory segment
will be responsible for indexing it for further processing.
By sharing the number of lines and columns of the memory segment plus
its data, each of your processes will be able to index it correctly.
You should be able to navigate through this memory chunk pretty easily
with the lines/columns you shared with it. The only trick is to
actually make sure these infos (meta-datas) are stored with it (like a
fixed-size header).

If you have more questions about it, ask them on comp.unix.programmer.

Feb 19 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Golf Nut | last post by:
I am finding that altering and affecting values in elements in multidimensional arrays is a huge pain in the ass. I cannot seem to find a consistent way to assign values to arrays. Foreach would...
by: slurper | last post by:
when i do this vector < vector<int> > p; later in the code i do things like this: vector<int> x,y,z; p.push_back(x); p.push_back(y); p.push_back(z);
by: Claire | last post by:
I have a multidimensional array defined as private double myArray = new double; The first column of the array contains X values, the other contains Y values I have a charting function defined as...
by: Ravi Singh (UCSD) | last post by:
Hello all I am trying to use jagged and multi-dimensional arrays in C++. In C# these work fine // for jagged arrays string jaggedArray = new string ; //for multidimensional arrays string...
by: andy.mcvicker | last post by:
Hi Gang I have a large VB program that at one point does a lookup to a small table (26 rows by 3 columns). With this table I have to do some counting and retrieval of data. I'm finding that...
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if...
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
by: zeny | last post by:
Hey everyone! Ive been tying to create a shared memory segment with the size of a structure, as follows: typedef struct{ int id; char message; }data; In the line where i create the shared...
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.