473,379 Members | 1,167 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,379 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
that.

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
thoughts?

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

my bad... ;)

-mike
Feb 19 '08 #2
ppi
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
thoughts?
You do not have many options here. You'd have better luck in
comp.unix.programmer.

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.

Cheers,
Paulo
Feb 19 '08 #3

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

Similar topics

5
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...
5
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);
3
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...
3
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...
4
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...
21
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...
10
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...
1
by: zeny | last post by:
Hey everyone! I´ve 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...
9
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...
0
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...
0
isladogs
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...
0
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...
0
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,...
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.