472,958 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 1973
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...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.