Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sharing Arrays?

94 views
Skip to first unread message

Nondisclosure007

unread,
Jul 22, 2011, 3:52:07 AM7/22/11
to
Ok. I get I can do this:
#pragma data_seg (".MYSEG")
int this_array[5];
#pragma data_seg()

But I want a "structured array". Not just an array of specific type
values.
ie.
#pragma data_seg (".MYSEG")
struct this_array { int v1; double v2; double v3; int v4; double
v5;};
#pragma data_seg()

Does this make sense? How can a "share' a structured array?

PS. I did figure out how to share data in my DLL from an earlier post.

Mikel

unread,
Jul 22, 2011, 5:03:13 AM7/22/11
to

A "collection" of things of different types is not an array. An array
is a collection of things (in C++, generally speaking, objects) of the
same type.
You can pack "objects" of different types in an struct or array,
mostly like you've done:
struct myStruct
{


int v1;
double v2;
double v3;
int v4;
double v5;
};

You can pass this mostly as any other object. And you can do arrays of
such objects too.

By the way, if possible, avoid C-style arrays (int whatever[5]).
Better use collection classes, like std::vector.

Nondisclosure007

unread,
Jul 22, 2011, 5:12:24 AM7/22/11
to
> Better use collection classes, like std::vector.- Hide quoted text -
>
> - Show quoted text -

Thanks. I think I figured out what I wanted to do:

struct SymbolData{double a; double b; double p; int s; int f;};

#pragma data_seg (".ARB")
SymbolData g_data1={0.0,0.0,0.0,0,0};
SymbolData g_data2={0.0,0.0,0.0,0,0};
#pragma data_seg()
#pragma comment(linker, "/SECTION:.ARB,RWS")

It's 2am where I'm at and I'm getting my terms mixed up. Sorry.

What do you think of the above?

Joseph M. Newcomer

unread,
Jul 22, 2011, 1:26:41 PM7/22/11
to
See below...
On Fri, 22 Jul 2011 00:52:07 -0700 (PDT), Nondisclosure007 <nondiscl...@gmail.com>
wrote:

>Ok. I get I can do this:
>#pragma data_seg (".MYSEG")
> int this_array[5];
>#pragma data_seg()

****
First, note that absolutely NOTHING USEFUL happens when you code the above. The
this_array will NOT be in the segment "MYSEG". If, on the other hand, you had written
int this_array[5] = {0};
then it would work; the data_seg is ignored if there is not an initialization clause
****


>
>But I want a "structured array". Not just an array of specific type
>values.
>ie.
>#pragma data_seg (".MYSEG")
> struct this_array { int v1; double v2; double v3; int v4; double
>v5;};
>#pragma data_seg()

****
How could it NOT make sense? It is perfectly valid C, and it works the same as any other
declaration. However, you MUST do an initialization clause if you want it in "MYSEG",
i.e.

struct this_array {int v1; double v2; double v3; int v4; double v5; } = {0};

or it will end up in the default data segment..

What you can't share is a pointer-to-something, e.g., you could not put a char* in (unless
you use based pointers, which is another completely separate discussion)
joe

*****


>
>Does this make sense? How can a "share' a structured array?
>
>PS. I did figure out how to share data in my DLL from an earlier post.

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer

unread,
Jul 22, 2011, 1:28:41 PM7/22/11
to
Note that you cannot use C++ collection classes in a shared data segment without massive
amounts of work!
joe

Nondisclosure007

unread,
Jul 22, 2011, 4:57:14 PM7/22/11
to
> email: newco...@flounder.com
> Web:http://www.flounder.com
> MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text -

>
> - Show quoted text -

Well, what I've got coded works.

Cholo Lennon

unread,
Jul 26, 2011, 5:32:34 PM7/26/11
to

A valid and more flexible alternative could be Boost.Interprocess
library (a header only library):

http://www.boost.org/doc/libs/1_47_0/doc/html/interprocess.html

Regards

--
Cholo Lennon
Bs.As.
ARG

0 new messages