473,387 Members | 1,282 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,387 software developers and data experts.

Alignment qualifier

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

Similar topics

4
by: Mahesh Tomar | last post by:
Dear Readers, I am porting my existing C code to C++. In my existing code there are numerous functions that has been defined with CONST qualifier. For eg. foo(const DATA_TYPE *x); DATA_TYPE is...
4
by: Shashi | last post by:
Can somebody explain how the byte alignment for structures work, taking the following example and considering: byte of 1 Byte word of 2 Bytes dword of 4 Bytes typedef struct { byte a; word...
67
by: S.Tobias | last post by:
I would like to check if I understand the following excerpt correctly: 6.2.5#26 (Types): All pointers to structure types shall have the same representation and alignment requirements as each...
7
by: Charles Sullivan | last post by:
On my system (using gcc) I found I need to use the "volatile" qualifier to limit compiler optimization. I notice that this qualifier is described in K&R 2nd edition (1988) but not in K&R 1st...
13
by: aegis | last post by:
The following was mentioned by Eric Sosman from http://groups.google.com/group/comp.lang.c/msg/b696b28f59b9dac4?dmode=source "The alignment requirement for any type T must be a divisor of...
12
by: Yevgen Muntyan | last post by:
Hey, Consider the following code: #include <stdlib.h> #define MAGIC_NUMBER 64 void *my_malloc (size_t n) { char *result = malloc (n + MAGIC_NUMBER);
4
by: Ben Petering | last post by:
Hi group, this is a 'best practice' type question (I want discussion of the issue - whys and why nots - similar to "casting the return value of malloc()", to cite an analogous case). Let's...
2
by: venkat | last post by:
Hi, i came across restrict qualifier while looking the code. I haven't able to understand what does this do?. Can some one help me how does this makes the things restrict to an specified...
9
by: istillshine | last post by:
It seems I never need to use it. It only made a long line longer, and made you type five more characters. I feel so strange why people are talking about it.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.