468,484 Members | 1,618 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

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

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
4 1795
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
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
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
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.

Similar topics

18 posts views Thread by Leslaw Bieniasz | last post: by
24 posts views Thread by Rv5 | last post: by
12 posts views Thread by Olaf Baeyens | last post: by
51 posts views Thread by Tony Sinclair | last post: by
350 posts views Thread by Lloyd Bonafide | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by gieforce | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.