473,383 Members | 1,877 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,383 software developers and data experts.

How to read content at an absolute memory address the quickest

1
Hi,
I'm trying to make my program read the content at a known memory address as fast as it can. I tried declaring that memory location as a variable (say 'aaaaa') normally as below:

unsigned int * aaaaa = (unsigned int *) 0xA0000008;

It compiled and retrieved the memory content at 0xA0000008 properly for me, except it took many assembly codes. This is because aaaaa is mapped to an internal code (say '012345') by my compiler. When running, 012345 is loaded into a CPU register, then the register content is used to get the memory address 0xA0000008, then the memory content is read from memory location 0xA0000008. (I read the assembly file generated by the compiler).

I would like the compiler to map aaaaa to 0xA0000008 instead, so that when running aaaaa (i.e. 0xA0000008) can be loaded into the CPU register, then the memory content pointed to by the register can be read right away, skipping one level of indirection.

Does anybody know how to write the C codes to get such effect?

Look forward to everybody's replies.

CCHMA
Sep 7 '11 #1
2 13411
weaknessforcats
9,208 Expert Mod 8TB
I know of no way to do this.

C/C++ all use logical addressing based on a flat address space. The logical address in your program is mapped by the operating system into an address that's valid for your process and the core in which it is running at the moment. You have no access to the absolute address.
Sep 7 '11 #2
Banfa
9,065 Expert Mod 8TB
That rather depends on your platform weaknessforcats.

There are plenty of microprocessor platforms where you have absolute access to the RAM (and FLASH too often).

Anyway I think you have misunderstood the OPs question, the extra step comes not from having to convert virtual to real address but rather having to load the address of aaaaa then load from that the address to access and then read that final address.

Of course eliminating 1 of those 3 steps is unlikely to make a big difference thinks would need to really critical to even consider trying.

However I would have thought using a const rather than a normal variable (especially in C++) might achieve it like so

Expand|Select|Wrap|Line Numbers
  1. const unsigned int * aaaaa = (unsigned int *) 0xA0000008;
  2. unsigned int value = *aaaaa;
  3.  
If that doesn't work then try using a macro, either a macro constant or a macro function

Expand|Select|Wrap|Line Numbers
  1. #define AAAAA ((unsigned int *)0xA0000008)
  2. unsigned int value = *AAAAA;
  3.  
Expand|Select|Wrap|Line Numbers
  1. #define READ_ADDRESS(x) (*((unsigned int *)x))
  2. unsigned int value = READ_ADDRESS(0xA0000008);
  3.  
All of these 3 methods attempt to remove the variable aaaaa as variable from the compiled program replacing it with an absolute address in the program. In the first case it should be compiled/optimised out because as a constant the compiler can optimise it away to an absolute value.

Of these 3 methods the first is most preferable, if it works, because it maintains the program structure and type system more rigorously. It is more likely to work in C++ than C though because consts in C++ are much more truly constant values than they are in C.
Sep 7 '11 #3

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

Similar topics

4
by: Askari | last post by:
Yesterday, ALL code in python work and nothing when I close(finish) a code. Today, when I close, some raise this windows error : Instruction at "0x00FC3D70" use memory address "0x00000000". Can't...
10
by: Dan Elliott | last post by:
I am working on some tricky code and need some help from the experts. I have several large data structures (uBLAS matrices) that must be written to a pre-allocated (by another program) chunk of...
4
by: Someonekicked | last post by:
Is it possible to read a memory address with C++; For example, If I run this code first: ************* #include <iostream> using namespace std; void main() { int *zz = new int;
5
by: Jeong-Gun Lee | last post by:
I'm writing a code of writing a value to a specific memory address. ================================================================= #include <stdio.h> int main() { long air; long...
37
by: kplkumar | last post by:
I want to get the memory address of an object. Can someone tell me how to do that in C#. Also, I tried using the unsafe and the "&" operator and could not acheive it. Can you tell me a good way of...
12
by: FI | last post by:
Hello All, I am relatively new to C programming and I am struck with a problem in dynamic memory allocation. I would like to know if it is ok to pass the 'memory address' returned by...
20
by: sethukr | last post by:
hi, i need to store a value to a particular memory location without having a variable. So, how can i access a 'memory address' without using variables?? Is it possible in C??? Plz, help...
15
by: polas | last post by:
Hi everyone - I have a question. I am just playing around with C (I realise there are better ways to do what I want, but I would like to do it this way to increase my understanding of C) and would...
5
by: erfan | last post by:
vc++6.0,winxp. I use this code to see the memory address and the real value`s address below: #include<stdio.h> int main() { int a=22; int *p; int i; p=&a;
1
by: nimad | last post by:
Hello, I would like to modify the content of the location bar (address bar) using JavaScript. Suppose I am at http://localhost/WebTests/TestEvent.aspx The followig line: window.location =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.