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

vPtr for an empty class

3
Hi, i have this code:

struct MenuChan
{
virtual void draw()=0;
};
struct MenuData_01
{
int nEast;
int nNorth;
char cId;
};
struct MenuChan_01: public PstarMenuChan, public MenuData_01
{
virtual void draw();
};


Im trying to send MenuData_01 structure data thru tcp and read it in the other side in order to convert it to MenuChan_01, the problem is that the size of thus two structure is different.

i get this results:
sizeof(MenuData_01)=12
sizeof(MenuChan_01)=16

i know that this space is populated by the vPtr but i don't know how to convert
the data i get to the MenuChan_01 class.

please help.
Feb 6 '08 #1
4 2014
weaknessforcats
9,208 Expert Mod 8TB
You do not want to send the sizeof(some struct). That sizeof includes, as you note, the VTBL pointer plus any slack bytes caused a word alignment. The target machine cannot use the vtbl address and possibly the slack bytes are different also dependingupon the target processor.

Send the the data members individually and build your object anew on the other side.
Feb 6 '08 #2
slamps
3
You do not want to send the sizeof(some struct). That sizeof includes, as you note, the VTBL pointer plus any slack bytes caused a word alignment. The target machine cannot use the vtbl address and possibly the slack bytes are different also dependingupon the target processor.

Send the the data members individually and build your object anew on the other side.
hi,
my problem is that i have many structures as the one mentioned above and I don't want to build specific code for each one of them.
is there any way to calculate the position of the VTABLE inside the structure?
Feb 6 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
is there any way to calculate the position of the VTABLE inside the structure?
I believe it is implementation dependent. Visual C++ uses the first 4 bytes of the object.

Microsoft uses a BSTR for stuff like this. A BSTR is a series of C strings separated by \0 with a final \0\0 marking the end of the string. The first part of the BSTR is the length. That way a receiver can read the first part, get the length, allocate the correct amount of memory,and then read the rest of that BSTR into to the allocation.

I suggest you convert your structs into a communications format object and that you work your communication in that format. So, you Unpack() to create a communications format object and the receiver calls a constructor using the communications format object to convert back to the original object.
Feb 6 '08 #4
slamps
3
I believe it is implementation dependent. Visual C++ uses the first 4 bytes of the object.

Microsoft uses a BSTR for stuff like this. A BSTR is a series of C strings separated by \0 with a final \0\0 marking the end of the string. The first part of the BSTR is the length. That way a receiver can read the first part, get the length, allocate the correct amount of memory,and then read the rest of that BSTR into to the allocation.

I suggest you convert your structs into a communications format object and that you work your communication in that format. So, you Unpack() to create a communications format object and the receiver calls a constructor using the communications format object to convert back to the original object.
I took your advise, thanks.
Feb 7 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Emmanuel Thomé | last post by:
This is a comment aside the empty class behavior FAQ. I understand there are a fair number of reasons which make empty classes have non-zero size (except as base classes). If ``class foo'' were...
12
by: Stefan Weiss | last post by:
Hi. (this is somewhat similar to yesterday's thread about empty links) I noticed that Tidy issues warnings whenever it encounters empty tags, and strips those tags if cleanup was requested....
9
by: Søren M. Olesen | last post by:
Hi Can someone tell me how to implement something similar to String.Empty ?? Given a class called myValue Public class myValue private id as integer private value as string end class
4
by: avranju | last post by:
Hi, We have a few exception marker classes in a project that are used only to throw exceptions. I mean stuff like this (this may not be such a hot idea for doing exception handling - a simple...
8
by: meendar | last post by:
what will a object of an Empty class( contain nothing), do on default.What are all the default methods it calls. what is the use of creating the object for an empty class?
7
by: Veeru | last post by:
Hi , What is the data type of Vptr pointer used in the virtual funtion mechanism? i suppose its void. Please correct me if i am wrong... Regards, Veeru
4
by: pai | last post by:
Hi, Can any body explain me about V-table and Vptr ( virtual pointer ). ANy link is also welcomed. I didnt get useful explation about the topic .I mean some what detail explation . As what...
4
by: Subhransu Sahoo | last post by:
Hi All, Can anyone tell me why the output of the following program is fx1 fx2 ? #include <iostream> using namespace std; class IX { public:
3
by: Rahul | last post by:
Hi Everyone, I was wondering what is the datatype of vtpr and what is its access specifier (public or private or protected)? This is in regard to the inheritance of a class having one or more...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.