Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > dynamic array through sockets(network)

Reply
Thread Tools

dynamic array through sockets(network)

 
 
Gurur
Guest
Posts: n/a
 
      09-13-2007
Hi all,

I have a doubt.
If I have 2 structures and one is parent of other , ie the child
structure is present in the parent one . And if the child structure is
declared as dynamic array in the parent , will it be possible to pass
the parent structure thru network using sockets onto other application
running on different system provided the API is known to both the
sender and the receiver.

For Ex:

struct Child
{
a: Int;
b: float;
}


struct parent
{
c : Int;
d : array of Child;(dynamic array)
}

If I make it static array, I will be able to pass it, but wat if it is
dynamic.

Thanks

 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      09-13-2007
Gurur wrote:

> If I have 2 structures and one is parent of other , ie the child
> structure is present in the parent one . And if the child structure is
> declared as dynamic array in the parent ,


C has no "dynamic arrays" as such; it has pointers and `malloc` instead.

> will it be possible to pass the parent structure thru network using
> sockets onto other application running on different system provided
> the API is known to both the sender and the receiver.


Of course. This being C, you just have to do "all" the work yourself.

> struct Child
> {
> a: Int;
> b: float;
> }


You're in the right newsgroup, yes? C? That's not C syntax.

> struct parent
> {
> c : Int;
> d : array of Child;(dynamic array)
> }
>
> If I make it static array, I will be able to pass it, but wat if it is
> dynamic.


If you're writing the code, it will do whatever you want.

If someone else writes the send-it-over-a-network code, it will do
whatever /they/ want, for which read their documentation / test cases.

--
If Any Hedgehog
"A facility for quotation covers the absence of original thought." /Gaudy Night/

 
Reply With Quote
 
 
 
 
Tor Rustad
Guest
Posts: n/a
 
      09-14-2007
Gurur wrote:
> Hi all,
>
> I have a doubt.
> If I have 2 structures and one is parent of other , ie the child
> structure is present in the parent one . And if the child structure is
> declared as dynamic array in the parent , will it be possible to pass
> the parent structure thru network using sockets onto other application
> running on different system provided the API is known to both the
> sender and the receiver.


Passing raw structures over a network between different systems, is a
rather bad idea.

For starters. The C structure layout in memory, is very much compiler
dependent. Just using a different C compiler option, might affect how
struct members are aligned.


Different type of encoding can be used (T=tag, L=length, V=value), for
fixed number of tags and fixed length:

V
V
....
V

an example here could be the IPv4 header:

0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| IHL |Type of Service| Total Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification |Flags| Fragment Offset |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Time to Live | Protocol | Header Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Destination Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

but notice the first 4 bits ('Version'), this is really a tag, so for
IPv6 header we can use a rather different header:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| Traffic Class | Flow Label |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Length | Next Header | Hop Limit |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Source Address +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Destination Address +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Hence, IP headers are an example of TV encoding!

For fixed number of tags and variable length:

LV
LV
LV
....
LV


Notice the "Total Length" or "Payload Length" field in the IP headers,
hence the IP payload is an example of LV encoding.

For variable number of tags and variable length, we could use:

TLV
TLV
....
TLV


Another option here, is to use start and end-tags, see e.g. XML and
EDIFACT. Likewise, an IP packet over Fibre Channel:

+-----+-----------+-----------+--------//-------+-----+-----+
| | | Data Field | | |
| SOF | FC Header |<--------------------------->| CRC | EOF |
| | | Optional | Frame | | |
| | | Header(s) | Payload | | |
+-----+-----------+-----------+--------//-------+-----+-----+

here Start-Of-Frame and End-Of-Frame, can be viewed as start and end
tags. One problem with end-tags, is that you can't have a payload
containing an end-tag, so when the length is unknown, such data need to
be escaped, just like when printing '%':

printf("%%");


> If I make it static array, I will be able to pass it, but wat if it is
> dynamic.


When using e.g. TLV, XML or EDIFACT encoding, dynamic number of data
elements can be handled at receiver. "Nobody" is sending raw C struct's
over the wire...

--
Tor <torust [at] online [dot] no>
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
looping through json array loops through the characters instead ofthe values Aaron Javascript 2 04-10-2011 05:58 PM
Array question - How dynamic is dynamic? Ruby Student Ruby 4 04-09-2009 12:59 PM
Sorting through an array of an array Dominic Son Ruby 5 10-13-2006 11:13 PM
Convert Static Array to Dynamic Array ? raxitsheth@gmail.com C Programming 2 07-14-2005 01:25 AM
Can a static array contain a dynamic array of pointers? Peter B. Steiger C Programming 8 04-26-2004 03:07 AM



Advertisments