I'm enjoying the book Effective C++. It has highlighted things that I've looked over, never heard of, or never even though of before! However, even with this book my understanding of C++ still doesn't seem to be solid.

For some time now I've been curious about how binary data is handled as well as developing efficient algorithms to improve performance. My curiosity grew after seeing a lot of posts here that strictly deal with data problems (conversions, casts, copying data, serialization and file I/O, binary algorithms, etc).

From what I understand, at some point or another, an object in C++ holds data based on the built-in types of C++ (and if it doesn't, I'd assume for that object to be a "tool" object, like pow or other math funcctions I suppose). What I want to understand is how to have better control of data and how it is represented in a class, structure, union or namespace. Basically a recommendation for a book that really goes in depth on how data is represented in all possible data containers.

For example, how is data (at the binary level) sorted in a struct or a class? In a union it's fairly straightforward (the amount of memory that's used in a union is shared across its members). For classes and structs I'd assume for it to be conditional (what separates the binary representation of the data, or is it simply "summed up?"). Additionally how does a namespace resolve data - is it different or the same as classes and structs?

Furthermore, is there a binary representation of the access level of the data, signature of the data, and parameters of the data? During serialization and file I/O, how is the information read and remembered?

So far, C++ has improved my understanding and ability to learn the concepts of programming in general. I am fairly confident that a book that covers a lot of these details in depth will improve my knowledge and help me progress without wondering how a lot of the good programmers here are just "so good." =)

If anyone has any recommendations of a book that has this information, please let me know!

Thanks,

-Alex

What I want to understand is how to have better control of data and how it is represented in a class, structure, union or namespace. Basically a recommendation for a book that really goes in depth on how data is represented in all possible data containers.

One of Ed's favorite books is Inside the C++ Object Model. You're asking for a lot of hardcore low level info, and I doubt you can get it all in one book, but that one is good for learning how compilers take your objects and store them.

Comments
Whoo! Thank you! =)

Data stored in classes / structures is not seperated by anything, it can almost be though of as a complex array that can hold different data types. That is how you can use reinterpret_cast so that another structure, or even just an array can get the data from the structure. Look at this example:

#include <iostream>
using namespace std;

struct A {
	char a, b, c, d, e, f;
};

int main() {
	A a;

	a.a = 'H';
	a.b = 'e';
	a.c = 'l';
	a.d = 'l';
	a.e = 'o';
	a.f = 0;

	char *str = reinterpret_cast<char*>( &a );

	cout << str;

	cin.ignore();
	return 0;
}

It seems to me like your interested in alot of the low level details, So I suppose I could recommend this book (even though I haven't got yet, but I plan on getting). It will definitely give you some knowledge about how this stuff works, as it even teaches you how to write your own assembler. It also has very good ratings. But most of this will be based on assembly language so make sure you know a bit before buying this book :P

Hope this helps.

Comments
I understand reinterpret_cast a little better - thank you for that and the book recommendation! =)

I have the Art of Assembly book, so learning Assembly to understand another book won't be too much of an issue. It'll just take time @_@

And thank you Radical Edward and vijayan121 for the recommendation of the same book - I plan to get that next =)

This article has been dead for over six months. Start a new discussion instead.