473,396 Members | 1,895 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,396 software developers and data experts.

Inserting a struct in a buffer

I have a buffer, which has a header and then data. There is some
leeway space between the header and the data in the buffer.

I have to add some more data which is a struct and I know the size of
it. So if I get a pointer to the beginning of the start of data, go
back the size of my struct, can I just put the address of my struct ?

Packet A -- Header + Data
Struct B --size X bytes

Pointer_to_Data
Pointer_to_Data = Pointer_to_Data - X

Is it recommended to copy the struct or can I just pass the address of
my sturct variable. If so how?

Thanks
Nov 3 '08 #1
1 2274
Slain wrote:
I have a buffer, which has a header and then data. There is some
leeway space between the header and the data in the buffer.

I have to add some more data which is a struct and I know the size of
it. So if I get a pointer to the beginning of the start of data, go
back the size of my struct, can I just put the address of my struct ?

Packet A -- Header + Data
Struct B --size X bytes

Pointer_to_Data
Pointer_to_Data = Pointer_to_Data - X

Is it recommended to copy the struct or can I just pass the address of
my sturct variable. If so how?
I am not sure what you're asking. Do you want to know how to take the
address of your struct? Use the '&' operator. Everything else if
really up to you. It is completely up to you whether to put the address
or the struct itself into your buffer. Does the struct live long enough
at the same address so that the pointer does not go invalid? If so, you
could use the address. Is it a short-lived struct, but the information
is valid for a long time, store the [copy of the] information itself.
You didn't provide enough detail to make the determination about that
design. And, you will have to forgive me, but I don't see any C++
language question in here, really. You seem to need to manipulate some
low-level values, like addresses in memory, which isn't really how C++
should be used...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 3 '08 #2

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

Similar topics

5
by: Roy Hills | last post by:
When I'm reading from or writing to a network socket, I want to use a struct to represent the structured data, but must use an unsigned char buffer for the call to sendto() or recvfrom(). I have...
0
by: Derrick | last post by:
I am trying to read a binary file into a struct, but am having trouble getting all the data. the struct and a snip of the code follows at the end of the message. Expected results: 'Sai,,LW,'...
5
by: Daniel Brown | last post by:
I am coding a managed C# wrapper for an unmanaged C DLL and I am unable to marshal a structure that contains an array of structures. When executed, the following code throws an ArgumentException...
8
by: cman | last post by:
What does this kind of typedef accomplish? typedef struct { unsigned long pte_low; } pte_t; typedef struct { unsigned long pgd; } pgd_t; typedef struct { unsigned long pgprot; } pgprot_t I am...
6
by: Jack | last post by:
Hi, All, is it possible to send a struct using the the send function. Here is what I mean typedef struct{ int ID; char name; }sampleStruct; int main(){
4
by: OhKyu Yoon | last post by:
Hi! I have a really long binary file that I want to read. The way I am doing it now is: for i in xrange(N): # N is about 10,000,000 time = struct.unpack('=HHHH', infile.read(8)) # do...
14
Parul Bagadia
by: Parul Bagadia | last post by:
Here is the code i hav written for inserting a no., after given no. in a link list; i guess the logic is ofcourse right. there is no error in it, but at the time of display its not displaying the...
8
by: sexauthor | last post by:
I'm converting a VB6 application over that called a 3rd party DLL with specific data structures. The VB6 code defined custom types for those data structures (ie: one with the specific data types,...
5
by: Chris Saunders | last post by:
Here is the C declaration of a struct from Windows: typedef struct _TXFS_READ_BACKUP_INFORMATION_OUT { union { // // Used to return the required buffer size if return code is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.