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

memory accesses

Adi
Hi,

I am writing a code which mimicks the memory accesses of an
application. Lets assume that array a[] contains all the addresses
accessed in sequence, check the for loop in the code given below. Now,
i want to mimick these accesses(not absolutely but atleast
relatively). I could see only one solution to that - writing a for
loop(see the code). But it gives extra memory accesses, accesing
address of index i and a[i] along with the to b mimicked accesses.

main()
{
int a[300]; //stores the addresses
char x[5000]; //character array to mimick the memory accesses
int i;

a[0] = 0;
for(i=1;i<300;i++)
a[i] = a[i-1]+16; //storing the addresses in the
array

x[0] = 0;
for(i=1;i<300;i++)
{
x[a[i]]='0'; //mimick the realtive memory
accesses.
}
}

Is there any other solution to bypass these unwanted accesses like
storing value of i in registers etc... ?

Thanks.
Nov 14 '05 #1
3 1115

"Adi" <pu********@yahoo.com> wrote in message
news:c8**************************@posting.google.c om...
Hi,

I am writing a code which mimicks the memory accesses of an
application. Lets assume that array a[] contains all the addresses
accessed in sequence, check the for loop in the code given below. Now,
i want to mimick these accesses(not absolutely but atleast
relatively). I could see only one solution to that - writing a for
loop(see the code). But it gives extra memory accesses, accesing
address of index i and a[i] along with the to b mimicked accesses.

main()
{
int a[300]; //stores the addresses
char x[5000]; //character array to mimick the memory accesses
int i;

a[0] = 0;
for(i=1;i<300;i++)
a[i] = a[i-1]+16; //storing the addresses in the
array

x[0] = 0;
for(i=1;i<300;i++)
{
x[a[i]]='0'; //mimick the realtive memory
accesses.
}
}

Is there any other solution to bypass these unwanted accesses like
storing value of i in registers etc... ?


How do you know that 'i' isn't already being stored in a register?

Profile your code before trying to second-guess your compiler.

-Mike
Nov 14 '05 #2
Adi
> >
main()
{
int a[300]; //stores the addresses
char x[5000]; //character array to mimick the memory accesses
int i;

a[0] = 0;
for(i=1;i<300;i++)
a[i] = a[i-1]+16; //storing the addresses in the
array

x[0] = 0;
for(i=1;i<300;i++)
{
x[a[i]]='0'; //mimick the realtive memory
accesses.
}
}

Is there any other solution to bypass these unwanted accesses like
storing value of i in registers etc... ?


How do you know that 'i' isn't already being stored in a register?

Profile your code before trying to second-guess your compiler.


I have profiled the code and i see 4 memory accesses(3 for i and 1 for
array a)between each access for x.
Nov 14 '05 #3

"Adi" <pu********@yahoo.com> wrote in message
news:c8**************************@posting.google.c om...

main()
{
int a[300]; //stores the addresses
char x[5000]; //character array to mimick the memory accesses
int i;

a[0] = 0;
for(i=1;i<300;i++)
a[i] = a[i-1]+16; //storing the addresses in the
array

x[0] = 0;
for(i=1;i<300;i++)
{
x[a[i]]='0'; //mimick the realtive memory
accesses.
}
}

Is there any other solution to bypass these unwanted accesses like
storing value of i in registers etc... ?


How do you know that 'i' isn't already being stored in a register?

Profile your code before trying to second-guess your compiler.


I have profiled the code and i see 4 memory accesses(3 for i and 1 for
array a)between each access for x.


And have you researched all the optimization switches of
your implementation? Have you proven that your code's
performance is somehow unacceptable? If so, perhaps you
need to drop down a level, and do this part with assembly
language, where you *can* have such low-level control.

-Mike
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: James Brown | last post by:
Hi again, I'm referring back to my previous posting of the same title, with everyone's help I've now got a better understanding of what my goals are and I have a class which now looks like: ...
3
by: narechk | last post by:
Consider: // points to a valid, alloc:ed, aligned memory location char* ptr_aligned = xxx; // same but unaligned obviously char* ptr_unaligned = xxx + 1; // write short val to aligned_ptr...
4
by: Metro12 | last post by:
Beyond my expectations, the result of the following program is 1 not 8. I want to know how the complier allocates memory for such a class, and why the class Test's size does not contain the struct...
34
by: Andrew | last post by:
Is there anyway to test if a pointer points to allocated memory or not? For example if I have a pointer such as char *p is there a standard way to test whether an assignment such as the following...
9
by: Andrew Au | last post by:
Dear all, I am trying to write a piece of software that use Object Oriented design and implement it with C, I did the following == In Object.h == typedef struct ObjectStructure* Object; ...
2
by: Janice | last post by:
My working system requires the starting address of a piece of data (an int, a long, etc.) must be a multiple of 4. If the requirement is not met, a segmentation fault occurs. My question is the...
31
by: William Stacey [MVP] | last post by:
Here is an interesting writing on memory barriers. Not sure if this helps my understanding or raises more questions, but interesting... ...
7
by: ballpointpenthief | last post by:
Hello, I'm thinking that it would be a good idea to start using the return code for main() to return the amount of memory still allocated (which would hopefully be zero) to ensure all memory has...
4
by: Bit byte | last post by:
I have a structure defined like this: struct foo { unsigned int magic ; void *mydata ; };
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.