memory problem on WM6 - ted

06-May-08 02:48:59
Hi, I develop system service in WM6. I have a problem with memory access.

I have defined this structure:

typedef struct
{
unsigned int item1;
unsigned int item2;
} ITEM;

and I would like to fill the memory by using it:

unsigned char *mem = new unsigned char[100];
if (mem != NULL) {
unsigned char *p_mem = (unsigned char *)&mem[9];

LOG(L"START");

((ITEM *)p_mem)->item1 = 0; // memory access error?! WHY?
((ITEM *)p_mem)->item2 = 0;

LOG(L"STOP"); // it will not be called anymore

delete[] mem;
}
button
 
 

memory problem on WM6 - Michael Salamone

06-May-08 09:31:32
Because it's unaligned access.  You need to have 4-byte aligned addresses
for int operation or ARM CPU coughs.
http://www.arm.com/support/faqdev/1469.html

You can either use aligned address (recommended) or you can use unaligned
access, but that generates additional instructions (which may or may not be
of concern to you depending if overhead is a concern for this bit of code).
Look up UNALIGNED macro.

--
Michael Salamone, eMVP
Entrek Software, Inc.
www.entrek.com
button
 

memory problem on WM6 - ted

06-May-08 12:17:18
Michael Salamone napsal(a):
Thanks a lot!! I have not know that so far.
button
 

memory problem on WM6 - ted

07-May-08 10:11:19
ted napsal(a):

but... __packed is not defined in VC++
button
 

memory problem on WM6 - Rick C

08-May-08 10:36:14
I haven't done a lot with making sure about alignments, but I suspect your
problem is with this line:

unsigned char *p_mem = (unsigned char *)&mem[9];

10 bytes into an array of char isn't 4-byte alignment.  If you can change
p_mem to point to &mem[8] (for example) I think that should get rid of the
problem.
button
 

memory problem on WM6 - Michael Salamone

08-May-08 10:52:32
Not "__packed".  "UNALIGNED".  That expands to "__unaligned".

So your struct def would be:

typedef struct
{
UNALIGNED unsigned int item1;
UNALIGNED unsigned int item2;
} ITEM;


--
Michael Salamone, eMVP
Entrek Software, Inc.
www.entrek.com
button
 
Loading service with Windows