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

Alignment qualifier

P: n/a
I work on embedded systems using C++ and frequently
need to create an interface that requires a pointer
to memory that is aligned to cache and/or page boundaries.
This is a typical requirement for DMA transfers.

What I think I would like, is a means to qualify a pointer
such that the compile-time type checking could ensure that
the client programs pass an appropriately aligned
argument to the interface.

Obviously, such a feature would require the programmer
to give the cache line size and page size to the compiler.

Has this been discussed before? References? Thoughts?

As this is my first posting to comp.lang.c++, I'm not
even certain that this is the appropriate forum.

--
Michael N. Moran (h) 770 516 7918
5009 Old Field Ct. (c) 678 521 5460
Kennesaw, GA 30144

"... abstractions save us time working, but they don't
save us time learning."
Joel Spolsky, The Law of Leaky Abstractions

The Beatles were wrong: 1 & 1 & 1 is 1
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Michael N. Moran wrote:
I work on embedded systems using C++ and frequently
need to create an interface that requires a pointer
to memory that is aligned to cache and/or page boundaries.
This is a typical requirement for DMA transfers.

What I think I would like, is a means to qualify a pointer
such that the compile-time type checking could ensure that
the client programs pass an appropriately aligned
argument to the interface.

Obviously, such a feature would require the programmer
to give the cache line size and page size to the compiler.

Has this been discussed before? References? Thoughts?

As this is my first posting to comp.lang.c++, I'm not
even certain that this is the appropriate forum.


I have started such a proposal for the standard by the encouragement of Herb
Sutter. However I am unaware of involvement of cache lines and pages sizes.
My proposal migth already be able to handle them (IMHO I have covered all
possibilities) but I may be wrong. If you don't mind please contact me on
this address or on attila dot f dot feher at ericsson dot com.

BTW I hope it is obvious from my previous words that standard C++ does not
support alignment specifications.

--
WW aka Attila
Jul 19 '05 #2

P: n/a
"Michael N. Moran" <mn*****@bellsouth.net> wrote in news:azO0b.94$o9.26
@fe03.atl2.webusenet.com:
I work on embedded systems using C++ and frequently
need to create an interface that requires a pointer
to memory that is aligned to cache and/or page boundaries.
This is a typical requirement for DMA transfers.

What I think I would like, is a means to qualify a pointer
such that the compile-time type checking could ensure that
the client programs pass an appropriately aligned
argument to the interface.

Obviously, such a feature would require the programmer
to give the cache line size and page size to the compiler.

Has this been discussed before? References? Thoughts?

As this is my first posting to comp.lang.c++, I'm not
even certain that this is the appropriate forum.


I'm afraid you're out of luck here. comp.lang.c++ is for Standard C++
discussions. Functions which will check for proper memory alignment are
necessarily plaform and/or implementation specific. You'll have to check
the documentation that came with your compiler, or find another newsgroup
specific to your particular target platform. Developers in those forums
will have likely encountered your specific problem before, and thus will be
able to give you much better advice than the people here (on this topic).
Jul 19 '05 #3

P: n/a
I don't think compile time checking is possible, as the addresses
are not known in advance.

You can easily add these checks to your DMA routines. Check if
the address passed to the function meets the alignment restrictions
like starting at a 16 byte boundary, 8 byte boundary etc.

The following article might also help:

http://www.eventhelix.com/RealtimeMa...ndOrdering.htm

Sandeep
--
http://www.EventHelix.com/EventStudio
EventStudio 2.0 - Generate Sequence Diagrams and Use Cases in PDF
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.