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

the address returned from "new" statement is 32 bit aligned?

P: n/a
Hi
i'm using intel P4.

when I write the statement like
char *p=new char[512]

what's the p value, is it aligned by 4 bytes? that's is p%4==0?
and, now I'm using the Intel SSE2 instruction to do some fast
algorthm, some instructions I need to move data from memory to XMM0
registers(which is 128 bits) should be be aligned on 16-byte
boundaries.

so, how can use these Instructions when I should take some operations
on data just "new" on the heap. Is there any suggestions to solve this
problems? thanks
Dec 26 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On 2007-12-26 07:30, Asm23 wrote:
Hi
i'm using intel P4.

when I write the statement like
char *p=new char[512]

what's the p value, is it aligned by 4 bytes? that's is p%4==0?
Platform/implementation specific, and therefore off topic in this group,
you could try asking in a group for your compiler/OS/platform.
and, now I'm using the Intel SSE2 instruction to do some fast
algorthm, some instructions I need to move data from memory to XMM0
registers(which is 128 bits) should be be aligned on 16-byte
boundaries.
I do not know how you use these instructions but I seem to recall that
there were special functions/instructions for putting data in special
128 bit data-types which will be operated on.

--
Erik Wikström
Dec 26 '07 #2

P: n/a
On Dec 26, 7:49*pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-12-26 07:30, Asm23 wrote:
Hi
i'm using intel P4.
when I write the statement like
char *p=new char[512]
what's the p value, is it aligned by 4 bytes? that's is p%4==0?

Platform/implementation specific, and therefore off topic in this group,
you could try asking in a group for your compiler/OS/platform.
and, now I'm using the Intel SSE2 instruction to do some fast
algorthm, some instructions I need to move data from memory to XMM0
registers(which is 128 bits) should be be aligned on 16-byte
boundaries.

I do not know how you use these instructions but I seem to recall that
there were special functions/instructions for putting data in special
128 bit data-types which will be operated on.

--
Erik Wikström
thanks, Erik, I have some answers on some visual studio forums, thanks
again for your help.

there is really some single instruction with SSE2 which could move
128bit data from memory to regsiter like XMM0.
Dec 26 '07 #3

P: n/a
Asm23 wrote:
Hi
i'm using intel P4.

when I write the statement like
char *p=new char[512]

what's the p value, is it aligned by 4 bytes? that's is p%4==0?
You'll have to look at the implementation (which you obviously are
if you're interfacing to assembler).

What the standard does guarantee is that
new char[X]

returns a piece of memory that is suitably aligned for any time
whose size is less than or equal to X.

Of course the Pentium doesn't have any real strict alignment
for any types, most compilers treat it as if they did for
some types such as double for efficiency.

I would guess (you'd have to experiment) that 4 byte alignment
is provided. Your other option would be to write your own
allocator.
Dec 26 '07 #4

P: n/a
On Dec 26, 10:56*pm, Ron Natalie <r...@spamcop.netwrote:
Asm23 wrote:
Hi
i'm using intel P4.
when I write the statement like
char *p=new char[512]
what's the p value, is it aligned by 4 bytes? that's is p%4==0?

You'll have to look at the implementation (which you obviously are
if you're interfacing to assembler).

What the standard does guarantee is that
* * * * new char[X]

returns a piece of memory that is suitably aligned for any time
whose size is less than or equal to X.

Of course the Pentium doesn't have any real strict alignment
for any types, most compilers treat it as if they did for
some types such as double for efficiency.

I would guess (you'd have to experiment) that 4 byte alignment
is provided. *Your other option would be to write your own
allocator.
Thanks Ron, I can solve my problems, here are the steps:
assume we want to get some buffer aligned by Y.
1, char *p=new char[X]
2, than exam the value of p, if p is not aligned by Y, I could use
char *q=p+d, which q is some deviation that make q is aligned by Y.

....

Last: delete[] p;
Dec 27 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.