0

When I have sizeof(utmp) , 384 is returned. So when I try to find out the size of the individual members, I get a different result. Using the method below, I come up with 382 bytes. Anyone know where I'm missing the other 2 bytes?

#include <iostream>
using std::cout;
using std::endl;

#include <utmp.h>

void size();

int main()
{
	size();
	return 0;
}

void size()
{
	utmp uLine;
	cout << "ut_type: " << sizeof(uLine.ut_type) << " bytes." << endl;
	cout << "ut_pid: " << sizeof(uLine.ut_pid) << " bytes." << endl;
	cout << "ut_line: " << sizeof(uLine.ut_line) << " bytes." << endl;
	cout << "ut_id: " << sizeof(uLine.ut_id) << " bytes." << endl;
	cout << "ut_user: " << sizeof(uLine.ut_user) << " bytes." << endl;
	cout << "ut_host: " << sizeof(uLine.ut_host) << " bytes." << endl;
	cout << "ut_session: " << sizeof(uLine.ut_session) << " bytes." << endl;
	cout << "ut_tv: " << sizeof(uLine.ut_tv) << " bytes." << endl;
	cout << "ut_addr_v6: " << sizeof(uLine.ut_addr_v6) << " bytes." << endl;
	cout << "ut_exit: " << sizeof(uLine.ut_exit) << " bytes." << endl;
	cout << "ut__unused: " << sizeof(uLine.__unused) << " bytes." << endl;
}
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by TheFueley
0

Just a guess, don't take this as gospel, but possibly the compiler is setting aside 384 bytes since 384 is a multiple of 4 and 382 isn't and for efficiency purposes, in a 32 bit system, the compiler only delegates memory in multiples of 4 bytes (4 bytes = 32 bits) for more efficient address calculation.

That's just one compiler novice's semi-educated guess.

0

Oh! That makes sense, that didn't even occur to me. Sounds good to me, thanks!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.