-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
I have couple of questions, I hope I can find the answers
here...(assuming the question are okay with this group)
A) what is memory alignment? I have a rough idea but cant clearly
understand it clearly...? If anyone has a pointer on net please tell
me.. I would be grateful...
Some told me that for memory to be aligned, the last 6 digits of the
address should be zero? is this correct?
Perhaps. Perhaps not. It depends on the internals of your platform.
"Memory alignment" is the recognition that the underlying platform may
have restrictions on where certain data types may be placed, in relation
to the space available in which to place them. Some platforms require
that certain data types be placed so that they start only on 'even
number addresses', or 'addresses that are divisible by 4' or some other
requirement. Some platforms have no requirements of this nature. The
requirement that limits the addresses that a data type can be placed at
is called "memory alignment".
The C standard specifies that malloc() and family will allocate memory
so that the address can be used for any data type. This means that
malloc() and family must be familiar with and able to accomodate the
restrictions the underlying platform place on the arrangement of data
items in memory. Not an easy task for portable code to accomplish, which
is why it is part of the implementation of a compiler.
B) so how can I write a function for example...
void * align_malloc(size_t size_of_memory_required, int
bit_alignement_required)
First off, your function will, by necessity, be specific to your
platform, and will not be portable.
Before you write such a function, you need to know
a) the mechanics of how your compiler arranges for a program to store
each data item. Typically, this will be an examination of the
assembly or machine code that your compiler generates, to determine
data type size, and store/load instruction type.
b) what restrictions your platform places on the placement of each data
type manipulated by the instructions generated by your compiler.
- From these, you can determine what machine restrictions your compiler
will have to contend with when accessing data types stored in an
align_malloc()'ed block of memory.
Once you have determined the restrictions, code your function to
allocate a block of memory, such that the block of memory starts at an
address that satisfies /all/ the alignment restrictions imposed by your
compiler on your platform. Then, return the address that the block
starts at.
Any help would be appreciated..
Thanks and advance
Dp
- --
Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
iD8DBQFCE5D1agVFX4UWr64RAqK2AKDnZcStlcuRODzkJ95P5r9QOfq20gCginP0
y7+QXCh6gDBSU7KxuxQK4JU=
=SDVo
-----END PGP SIGNATURE-----