Calculating space efficiency using sizeof()
When calculating for space efficiency, do I have to calculate everything, or just the node size?
For example:
Let's say I have a linked list structure. It consists of a string, and a pointer to the next node. The string is "hello":
Code:
struct test
{
char* a;
test* next;
};
a = malloc(5);
strcpy(a, "hello");
structure = 4 bytes
char * = 4 bytes
next node * = 4 bytes
size of 'hello\0' = 5 bytes
total = 17 bytes?
or should the total just be 9 bytes (size of hello and size of pointer to next node) ?
I'm doing this using the sizeof() function to calculate how much "space" I need. Hope you guys understand what I'm talking about :)