473,320 Members | 2,080 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,320 software developers and data experts.

Marshalling an array of Structures

Hi All,

I don't know whethher this is possible or not. This is the result of a
bad design problem.

Here I go; I have a structure like this:

typedef struct _s_index_entry {
char *doc_id;
double s_id;
} S_INDEX_ENTRY;

And I have mappings of a keyword and a corresponding array of
S_INDEX_ENTRYs described above or:

S_INDEX_ENTRY **sie; which is the case. The length of the double
pointer is also not fixed.

I need to save it to a BerkeleyDB or send it to a client TCP socket. So
I need to marshall all the data and do the needful. I have done
marshalling on a structure but am completely at a loss for marshalling
this array of structures. Is it possible to do this through C.

Also is it possible to marshal a quee of structures which seems to be
another way to get my data accross. Save the array of structures as a
queue of structures and do the code, but that also seems similar.

Thanks in Advance,
-Animesh

Nov 15 '05 #1
4 2835
"Animesh" <an*****@neolinuxsolutions.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
....
typedef struct _s_index_entry {
char *doc_id;
double s_id;
} S_INDEX_ENTRY; .... I need to save it to a BerkeleyDB or send it to a client TCP socket. So


I hope you don't send *pointers* in the network packets as on the other PC
they will all be considered broken unless somehow you manage to align memory
allocation on both sending and receiving PCs... Send raw data and indices
into arrays, but not the pointers, pointers are meaningless on the other PC.

Alex
Nov 15 '05 #2
That's what - I cannot send pointers and hence I need to marshall the
entire data which could be packed off as a data stream over TCP.

When I have a single structure to be passed, its OK and something like:
http://mm.ilug-bom.org.in/pipermail/...05/021783.html

I want to do similar stuff for an array of Structures. Any help or
pointers.

Regards,
Animesh

Nov 15 '05 #3


Animesh wrote:
Hi All,

I don't know whethher this is possible or not. This is the result of a
bad design problem.

Here I go; I have a structure like this:

typedef struct _s_index_entry {
char *doc_id;
double s_id;
} S_INDEX_ENTRY;

And I have mappings of a keyword and a corresponding array of
S_INDEX_ENTRYs described above or:

S_INDEX_ENTRY **sie; which is the case. The length of the double
pointer is also not fixed.

I need to save it to a BerkeleyDB or send it to a client TCP socket. So
I need to marshall all the data and do the needful. I have done
marshalling on a structure but am completely at a loss for marshalling
this array of structures. Is it possible to do this through C.

Also is it possible to marshal a quee of structures which seems to be
another way to get my data accross. Save the array of structures as a
queue of structures and do the code, but that also seems similar.


<off-topic>

If you're using some kind of standard marshalling protocol,
the sort of thing that RMI implementations rest on, you'll most
likely find that the problem of encoding a sequence of objects
has already been solved. Check the documentation. Do this
first before looking for "pure C" solutions: C doesn't have any
so you'll need to roll your own, but if you can take advantage
of something that's already been written and debugged you'll
be well ahead of the game.

</off-topic>

You already have some way of encoding "Here comes a
struct foo" or "Here comes an int" in your outgoing data
stream. It might be an explicit encoding involving type
codes and such, or perhaps it's implicit in the organization
of the data stream. In any event, you say you've already
got suitable conventions for encoding one struct instance.

To encode a sequence, you need just a little more
"decoration" beyond what you've already put together. This
would probably take one of these forms:

- A prefix meaning "Here comes a sequence of N struct foo
instances," followed by N encoded structs.

- A prefix meaning "Here comes a sequence of N somethings,"
followed by the N encoded somethings, each introduced by
its own "Here comes a struct foo" or "Here comes a
struct bar" prefix. More verbose than the first method,
but also more flexible.

- A prefix meaning "Here comes a sequence of struct foo
instances," followed by the encoded structs, followed
by a suffix meaning "That was the last one."

- The same verbosity- and flexibility-increasing variation:
"Here comes a sequence of somethings" followed by the
encoded somethings, each with its own prefix, followed
by a suffix meaning "That's all, folks!"

Choose the method (or variation) that fits most comfortably
with the encoding protocol you're already using for single
objects.

--
Er*********@sun.com

Nov 15 '05 #4

Thanks Eric,
- A prefix meaning "Here comes a sequence of N struct foo
instances," followed by N encoded structs.


This is what I ave been doing, though the prefix contains the number of
elements in the array of structures. I need to first complete the
Berkeley DB Addition then I could go ahead with the Network I/O.

For the BDB part there are more issues with byte alignment which I am
currently working on.

Regards,
Animesh

Nov 15 '05 #5

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

Similar topics

3
by: PHil Coveney | last post by:
Hello, I am having difficulty marshalling structures when calling DeviceIoControl. I am importing this Win32 function as static extern int DeviceIoControl (int hDevice, int...
7
by: Mick | last post by:
Does anyone know how to pass an array of structures to a DLL? Here's what I'm doing... the VB.Net error is at the end. *** C++ Structure Declaration: typedef struct _SOME_STRUCT { char...
4
by: emma middlebrook | last post by:
Hi Straight to the point - I don't understand why System.Array derives from IList (given the methods/properties actually on IList). When designing an interface you specify a contract. Deriving...
1
by: Reynardine | last post by:
I am calling a C/C++ DLL from C# and I am marshalling the parameters to the API call by doing a type conversion for each parameter. For example, here is my C++ API method : short int XENO_API...
5
by: PickwickBob3 | last post by:
I am trying to obtain a list of HID devices and am trying to use UINT GetRawInputDeviceList( PRAWINPUTDEVICELIST pRawInputDeviceList, PUINT puiNumDevices, UINT cbSize); a USER32.dll. but...
0
by: PickwickBob3 | last post by:
I have a question about how to marshal the PRAWINPUTDEVICELIST pRawInputDeviceList which is --- > Pointer to buffer that holds an array of RAWINPUTDEVICELIST structures for the devices attached to...
1
by: peary | last post by:
Hi, everyone, I'm writing a program to discover wireless network using Windows Native Wifi API & VB.net. I have to declare the windows API in my VB.net program. The original windows...
2
by: calenlas | last post by:
Hi all, I'm taking my first steps into C# <--C++ DLL Interop and unfortunately I've run into (what seems to be) a very complicated case as my first task. Perhaps someone here can help me. I...
1
by: roche72 | last post by:
I am having some trouble marshalling data between c++/C# Here is the C++ code: --------------------------------------------------------------------------------- typedef struct { ...... ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.