| View previous topic :: View next topic |
| Author |
Message |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Thu Mar 19, 2009 2:34 pm Post subject: Array storage in Memory |
|
|
When you make an Integer value, lets for instance take 133337, it will be stored in the memory as the following:
because 133337dec = 000208D9hex, and backwards
But what if i took an array of ints, lets say
| Code: | | int var[2] = {133337, 1333337, 13333337}; |
How would it be stored then?, like this?:
| Code: |
var[0] var[1] var[2]
D9 08 02 00 59 58 14 00 59 73 CB 00 |
Or how would it be stored?
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Thu Mar 19, 2009 2:36 pm Post subject: |
|
|
Yeah.
The way the compiler accesses the location of an index of an array is with this simple algorithm:
| Code: |
Location = ArrayBase + Index * sizeof( DataType )
|
_________________
|
|
| Back to top |
|
 |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Thu Mar 19, 2009 3:14 pm Post subject: |
|
|
| samuri25404 wrote: | Yeah.
The way the compiler accesses the location of an index of an array is with this simple algorithm:
| Code: |
Location = ArrayBase + Index * sizeof( DataType )
|
|
So, if var was located at 00400000 accessing var[2], where var is an array of integers, it would be at 0040000C?
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Thu Mar 19, 2009 3:20 pm Post subject: |
|
|
| Anden100 wrote: | | samuri25404 wrote: | Yeah.
The way the compiler accesses the location of an index of an array is with this simple algorithm:
| Code: |
Location = ArrayBase + Index * sizeof( DataType )
|
|
So, if var was located at 00400000 accessing var[2], where var is an array of integers, it would be at 0040000C? |
No, it would be 00400008.
1st integer = 00400000 = var[0]
2nd integer = 00400004 = var[1]
3rd integer = 00400008 = var[2]
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Thu Mar 19, 2009 3:31 pm Post subject: |
|
|
| smartz993 wrote: | | Anden100 wrote: | | samuri25404 wrote: | Yeah.
The way the compiler accesses the location of an index of an array is with this simple algorithm:
| Code: |
Location = ArrayBase + Index * sizeof( DataType )
|
|
So, if var was located at 00400000 accessing var[2], where var is an array of integers, it would be at 0040000C? |
No, it would be 00400008.
1st integer = 00400000 = var[0]
2nd integer = 00400004 = var[1]
3rd integer = 00400008 = var[2] |
What if the variables were WORD or BYTE ;O
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Thu Mar 19, 2009 3:38 pm Post subject: |
|
|
| S3NS4 wrote: | | smartz993 wrote: | | Anden100 wrote: | | samuri25404 wrote: | Yeah.
The way the compiler accesses the location of an index of an array is with this simple algorithm:
| Code: |
Location = ArrayBase + Index * sizeof( DataType )
|
|
So, if var was located at 00400000 accessing var[2], where var is an array of integers, it would be at 0040000C? |
No, it would be 00400008.
1st integer = 00400000 = var[0]
2nd integer = 00400004 = var[1]
3rd integer = 00400008 = var[2] |
What if the variables were WORD or BYTE ;O |
WORD = 2 bytes
BYTE = 1 byte
so add respectively
|
|
| Back to top |
|
 |
|