Alignment qualifier

Discussion in 'C++' started by Michael N. Moran, Aug 20, 2003.

  1. 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
    Michael N. Moran, Aug 20, 2003
    #1
    1. Advertising

  2. Michael N. Moran

    White Wolf Guest

    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
    White Wolf, Aug 20, 2003
    #2
    1. Advertising

  3. Michael N. Moran

    Andre Kostur Guest

    "Michael N. Moran" <> 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).
    Andre Kostur, Aug 25, 2003
    #3
  4. Michael N. Moran

    Sandeep Guest

    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/RealtimeMantra/ByteAlignmentAndOrdering.htm

    Sandeep
    --
    http://www.EventHelix.com/EventStudio
    EventStudio 2.0 - Generate Sequence Diagrams and Use Cases in PDF
    Sandeep, Aug 26, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hiwa
    Replies:
    4
    Views:
    477
    Oliver Wong
    Mar 8, 2006
  2. Sergey Tolstov

    const qualifier and VC6.0

    Sergey Tolstov, Oct 7, 2003, in forum: C++
    Replies:
    8
    Views:
    463
    Howard
    Oct 7, 2003
  3. A
    Replies:
    5
    Views:
    3,406
    Victor Bazarov
    Nov 27, 2003
  4. bardos
    Replies:
    2
    Views:
    759
    Old Wolf
    Aug 30, 2004
  5. Mahesh Tomar

    Const Qualifier question

    Mahesh Tomar, Sep 1, 2004, in forum: C++
    Replies:
    4
    Views:
    360
    Old Wolf
    Sep 2, 2004
Loading...

Share This Page