By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,612 Members | 1,656 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,612 IT Pros & Developers. It's quick & easy.

overload new , size is strange

P: n/a
Hi, gurus

I've overloaded new operator. and I found that size is strange.
It's more than sizeof(myClass) 4 bytes.
Where does it come from.

I don't know the other compilers do the same thing.
This may be bug of gcc.

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Prawit Chaivong wrote:
Hi, gurus

I've overloaded new operator. and I found that size is strange.
It's more than sizeof(myClass) 4 bytes.
Where does it come from.

I don't know the other compilers do the same thing.
This may be bug of gcc.


Compilers are allowed to insert as much padding into objects as they
like. The standard usually only talks about the bytes that participate
in the object's value representation.

Jacques.
Jul 23 '05 #2

P: n/a


Prawit Chaivong wrote:
Hi, gurus

I've overloaded new operator. and I found that size is strange.
It's more than sizeof(myClass) 4 bytes.
Where does it come from.

I don't know the other compilers do the same thing.
This may be bug of gcc.


Sorry, Please ignore previous post. I was confusing.
The real situation is that I overload new and new[].
---------------------------------------------
void* MyClass::operator new(size_t size);
and
void* MyClass::operator new[](size_t size);
----------------------------------------------
In new size = 20; //assume
whilst in new[], size = 204;

In my opinion, it should be 200.
Where does more 4 bytes come from?

Regards,

Jul 23 '05 #3

P: n/a

"Prawit Chaivong" <pr******@gmail.com> skrev i en meddelelse
news:11**********************@g49g2000cwa.googlegr oups.com...


Prawit Chaivong wrote:
Hi, gurus

I've overloaded new operator. and I found that size is strange.
It's more than sizeof(myClass) 4 bytes.
Where does it come from.

I don't know the other compilers do the same thing.
This may be bug of gcc.


Sorry, Please ignore previous post. I was confusing.
The real situation is that I overload new and new[].
---------------------------------------------
void* MyClass::operator new(size_t size);
and
void* MyClass::operator new[](size_t size);
----------------------------------------------
In new size = 20; //assume
whilst in new[], size = 204;

In my opinion, it should be 200.
Where does more 4 bytes come from?

Regards,

Probably gcc uses four bytes to store the number of elements in the array.
Why don't you use std::vector?

/Peter
Jul 23 '05 #4

P: n/a
Jacques Labuschagne wrote:

Compilers are allowed to insert as much padding into objects as they
like. The standard usually only talks about the bytes that participate
in the object's value representation.

They are allowed to insert padding WITHIN objects, but they can not
insert padding between objects nor will they call the allocation
function with more than sizeof (T).

The array form of the allocator can have some constant overhead added
to the n*sizeof(T).
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.