gcc (GCC) 4.7.0 c89
I am allocating memory using the following:
db_data_size = 32;
db->db_data[i]->name = malloc(db_data_size);
(gdb) p db_data_size
$24 = 32
(gdb) p sizeof(db->db_data[i]->name)
$25 = 8
(gdb) n
205 db->db_data[i]->email = malloc(db_data_size);
(gdb) p sizeof(db->db_data[i]->name)
$26 = 8
In the debugger I get 8 bytes instead of the 32 bytes I think should have been allocated.
My structure is:
struct data {
int id;
int set;
char *name;
char *email;
};
struct database {
struct data **db_data;
size_t database_rows;
size_t database_data_size;
};
The only think I can think of is that a char* is 8 bytes, and that is what I am getting. However, in malloc I have explicity asked for 32 bytes.
tells you the size of
which is the size of a pointer (to char). It does not tell you the size of the allocated block; if you need to remember that, you must store it separately.
So
8is the correct answer for a pointer on a 64-bit system.