4 ms·
where's the difference if you put in the numbers by hand? Which numbers do you put in to avoid mentioning the size of the type?
by posterboy 8y ago
where's the difference if you put in the numbers by hand? Which numbers do you put in to avoid mentioning the size of the type?
- kevin_thibedeau 8y agoYou just feed sizeof the instance of the object you're allocating memory for. That entails funky pseudo-dereferences for pointers so the compiler doesn't give you the size of a pointer. It will look up the object's type and requisite size to fill in the argument to malloc(). If the object in question has an unknown type (maybe all you've got is a void *) then you will have to provide the size by other means.