473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 1987
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Leslaw Bieniasz | last post by:
Cracow, 28.10.2004 Hello, I have a program that intensively allocates and deletes lots of relatively small objects, using "new" operator. The objects themselves are composed of smaller...
24
by: Rv5 | last post by:
Rookie c++ question, but Ive spent the last 5 years doing Java, where everytime I created an object I used new. In c++ I can create my objects without and its confusing me just a little. I have...
12
by: Olaf Baeyens | last post by:
I am porting some of my buffer class code for C++ to C#. This C++ class allocates a block of memory using m_pBuffer=new BYTE; But since the class is also used for pointers for funtions that uses...
51
by: Tony Sinclair | last post by:
I'm just learning C#. I'm writing a program (using Visual C# 2005 on WinXP) to combine several files into one (HKSplit is a popular freeware program that does this, but it requires all input and...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
350
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.