How to align a global array in C.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajivatbytes
    New Member
    • Sep 2008
    • 3

    #1

    How to align a global array in C.

    I need a global array in C to be aligned (say 64 Bytes) to store a data of oder of KBs.

    I don't want to do dynamic allocation as this would be copy of huge data.


    any suggestion will be appreciated.

    Thanks in advance.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Memory for global data may be limited.

    I suggest you use the heap.

    Why 64-byte alognment?

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      What is the array type (array of shorts, ints, longs, structures)?

      Is your alignment criteria any more stringent than that imposed by your processor on a single element of the array?

      Comment

      • rajivatbytes
        New Member
        • Sep 2008
        • 3

        #4
        Originally posted by weaknessforcats
        Memory for global data may be limited.

        I suggest you use the heap.

        [rajivatbytes]: its so required as data is some DSP codec which would be copied on DSP RAM on need basis.

        Why 64-byte alognment?
        [rajivatbytes]: its some hardware requirement.

        Comment

        • rajivatbytes
          New Member
          • Sep 2008
          • 3

          #5
          Originally posted by donbock
          What is the array type (array of shorts, ints, longs, structures)?
          [rajivatbytes]: its an array of integer(i guess data type should not effect).

          Is your alignment criteria any more stringent than that imposed by your processor on a single element of the array?
          [rajivatbytes]: all data should be contagious(very nature of array) and first member of the array should be at the address which is aligned at 64K boundary.
          please find my comment inline.

          Thanks,

          Comment

          • donbock
            Recognized Expert Top Contributor
            • Mar 2008
            • 2427

            #6
            There is no portable way in C to insure some arbitrary alignment for a static variable. (By "arbitrary" I mean that the alignment requirement is unrelated to the data type of the static variable; not that you don't have a good reason for it.)

            That said; there are nonportable ways to achieve a desired alignment. Some compilers provide special keywords for setting the alignment (#pragma, __attribute__, etc.). Some linkers provide syntax for aligning particular memory segments. It all depends on which compiler and linker you're using.

            Comment

            Working...