----- Mark Broadbent wrote: ----
[color=blue]
> The purpose for all my questions stems from the fact that I am trying t
> comprehend what the hell is the point of being able to increment/increase o
> decrement/decrease (via ++ -- +num -num) a pointer so that it points t
> another element/memory location IF you cant positionally know what the nex
> variable element/s are going to be. I therefore believe (although yo
> suggest that this is not the case) that variables (by declaration) ar
> stored in memory in reverse order (next to each other) for the duration o
> their lifecycle[/color]
I don't think (could be wrong) that there is a reliable pattern to how variables are laid out in memory relative to each other. if fact, if you add more variables to your code, you will see there is no clear pattern. increment/decrement is typically used with array of a value type, where elements of the array are laid out in sequential block, and you know the size of each element. so you know the boundary of the array and can safely walk it. Is there a reason why you would need to use the pointer to one variable as a relative jump location to other variables in memory
[color=blue]
> The reason that knowing the physical structure of data types is importan
> with relation to pointers is that you may want to use a int* pointer (an
> increment/decrement it) to modify a whole range of memory locations o
> different types -without causing a program exception because you have jus
> set an invalid value to the second byte of a double[/color]
why? what advantage would that have over modifying a double as a double (besides the fact that it's cool)? but I'm sure that information is out there, I just never had to do it
--
Br
Mark Broadben
mcdba,mcse+
======================
"Morten Wennevik" <MortenWennevik@hotmail.com> wrote in messag
news:opr4cf2yq0hntkfz@msnews.microsoft.com..[color=blue]
> On Thu, 4 Mar 2004 14:54:01 -0000, Mark Broadben
><no-spam-please@no-spam-please.com> wrote[color=green][color=darkred]
>>> hi all. Ive been looking into the use of pointers to try and get my hea[/color]
>> around them which has led me onto a question
>> 1. How do you know what memory position C# compiler will use for eac
>> variable declaration as this example shows they seem to be stored i
>> reverse order of declaration (see code below). Is this always the cas
>> -so that you can guarantee which variable you are effectively hitting[color=darkred]
>>> You don't, and the garbage collector will change the positions too. Eac[/color][/color]
> new allocation will be put ontop of everything else, causing memor
> allocation to be faster than in C/C++. But the garbage collector wil
> change the position when it releases objects that have been allocate
> earlier so that there are no free memory "holes". There is no way o
> knowing (as far as I know) "where" an object is at any given moment
> Assuming you aren't using unsafe[color=green]
>> But since C# also don't use pointers to objects, but references, you don'[/color]
> worry about it. The reference table will be changed by the garbag
> collector when needed, but the reference will always point to the correc
> object even if it may move around inside memory[color=green][color=darkred]
>>> 2. Where can I find out how the physical binary (or byte[/color]
>> representation o
>> numbers signed and unsigned(and other types) Please give me a good tex
>> re
>> that describes it such as a url)]? One reason being is because I migh
>> hav
>> an int pointer (which increments by byte) and increment it so it point
>> t
>> the first byte of a double -to make a change to this byte I would nee[/color][/color]
t[color=blue][color=green]
>> know how the double is physically represented across both bytes
>> otherwise
>> would not be able to determine the resulting outcome of the doubl
>> itself
>> Another reason I found was to accurately predict the result of bitwis
>> shifting of numbers (i.e. what i would expect and what i got!)[color=darkred]
>>>> hope this all made sense,[/color]
>> What exactly are you trying to achieve? One of the major benefits of C#[/color]
> is that it doesn't use pointers.
> You can still use them in an unsafe codeblock in C# though. Can't help
> you with the sizes though.[color=green][color=darkred]
>>> --[/color][/color]
> Using M2, Opera's revolutionary e-mail client:
http://www.opera.com/m2/[/color]