473,396 Members | 2,002 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,396 software developers and data experts.

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.
Sep 29 '08 #1
5 4454
weaknessforcats
9,208 Expert Mod 8TB
Memory for global data may be limited.

I suggest you use the heap.

Why 64-byte alognment?
Sep 29 '08 #2
donbock
2,426 Expert 2GB
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?
Sep 29 '08 #3
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.
Sep 29 '08 #4
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,
Sep 29 '08 #5
donbock
2,426 Expert 2GB
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.
Sep 29 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: miguel | last post by:
I have a number of global variables declared, like so: /** * @global string $GLOBALS * @name $foo */ $GLOBALS = 'something'; /** * @global string $GLOBALS
3
by: K B | last post by:
I have an application that loads an array in the global ASA file. Sometimes that array gets lost for no real reason, resulting in a ubound error. MS has a solution which involves removing...
1
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
7
by: Ekim | last post by:
hello, I'm using MANAGED C++ and need one of the following two questions answered: 1.) How can one make a global managed array? I'm thinking on something like defining static System::Byte...
8
by: john townsley | last post by:
whats the best way to declare Global objects (holding say 10 member variables and functions) of an unknown size in c++, memory efficient as possible thanks
35
by: whisper | last post by:
My question is whether it is better to use a global variable to hold a dynamically malloced multidim array or pass around pointers to it. The details are below (forgive the long winded explanation)...
12
by: a | last post by:
def fn(): for i in range(l) global count count= .... how do i declare count to be global if it is an array subsequently i should access or define count as an array error:
3
by: Jeff | last post by:
Quick questions I can't find answers to: Is there a shortcut to do this: if(! $some_var){$some_var = 'some_other_value'} I'm used to this: $some_var ||= 'some_other_var'; PHP manual doesn't...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.