TI E2E Community (Beta)
Welcome to the TI E2E (Engineer-to-Engineer) Community! We invite you to freely and openly interact with your peer Engineers, TI Engineers, and other experts in order to ask questions, share knowledge, explore ideas, and help solve problems.
More Search Options

Memory map prevented read of target memory

rated by 0 users
Answered (Verified) This post has 1 verified answer | 5 Replies | 3 Followers

Not Ranked
3 Posts
Community Member
Ates Dumlupinar posted on 23 Oct 2009 2:04 PM

Hi,

I'm having problems using pointers. Even the simplest thing:

Uint16 *x;

*x =5;

does not work. In the watch window for variable *x it displays:

memory map prevented read of target memory at 0xEA689946@Data. What do I need to do?

Answered (Verified) Verified Answer

Top 10 Contributor
648 Posts
Texas Instruments Employee

Hi,

You need to give the pointer X a value before you fill the memory location pointed by it.

Right now you want to fill the memory location pointed by X, but you did not say where should be that location...

If you do not give X a value (initialize the pointer), it can point to whatever was in the X variable and that can fall in a non- mapped area...

All Replies

Top 10 Contributor
648 Posts
Texas Instruments Employee

Hi,

You need to give the pointer X a value before you fill the memory location pointed by it.

Right now you want to fill the memory location pointed by X, but you did not say where should be that location...

If you do not give X a value (initialize the pointer), it can point to whatever was in the X variable and that can fall in a non- mapped area...

Not Ranked
3 Posts
Community Member

How can I assign just the next available address location to X then? And how can I make sure that anything I define say 'int y' is not written to where I decleare X at?

Top 50 Contributor
103 Posts
Community Member

Hi,

As far as assigning next available address is concerned, you can increment tje address where variable 'x' is stored by 1 and store the new variable in that address.

To make sure that the new variable say int y does not get written to the location where X is defined, you can use the #pragma directive to explicitly define the memory locations where you want your variables to be stored.

the #pragma directive overrides compiler based options and helps you assign variables to specific memory locations as per your requirement. You can then define this specific memory location in your .cmd file i.e. linker file (assuming you are using Code Composer Studio since you mentioned using watch window in your earlier post)

Regards,

Sid

Not Ranked
3 Posts
Community Member

I still don't get why I have to worry about this. When I define

int x;

I never have to think where code composer defines the variable x and whether it is in the memory map or not because it does its job correctly everytime. How come when I define a pointer it can't do the same?

Top 200 Contributor
41 Posts
Texas Instruments Employee

Ates,

int x; and int*x; are two different things.

They are similar in allocation. When you have int x; or int *x; in your code, the linker will allocate a space (of size int for the first and of size memory address for the second) in a valid place in memory (according to the linker map file, obviously). You can assign a value to it by simply using the equal (=) operator,  since there is memory space reserved to it. However the similarities end here.

When you assign a value to the variable x, you are writing a numeric value to the integer but an address to the pointer. Therefore when using the dereference (*) operator *x = 5;  you are actually telling the compiler to store the value (5) in the memory address previously stored in the variable x. If x contains a random value, you are actually trying to write the value to a random point in your memory space, either valid or invalid.

That's the reason why you need to initialize the pointer variable before assigning a value to it.

There are several other nuances and details about this extensive subject. Please check around on the internet about pointers - a particularly useful page is located here:

http://www.cplusplus.com/doc/tutorial/pointers/

Hope this helps,

Rafael

 

 

Page 1 of 1 (6 items) |

ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". TI AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY TI. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.