[Gambas-user] gb3: writing variables to a string using a memory stream and pointer

Kevin Fishburne kevinfishburne at ...1887...
Tue Sep 13 20:07:41 CEST 2011


On 09/13/2011 04:59 AM, Benoît Minisini wrote:
>> On 09/12/2011 10:24 PM, Benoît Minisini wrote:
>>>>> ' Create data string.
>>>>> DataPointer = Alloc(8)
>>>>> Mem = Memory DataPointer For Read Write
>>>>> Write #Mem, (Server.DateCurrent + Server.DateUTC) As Float
>>>>> Data = Read #Mem As Float
>>>>> Print "Original: "&   (Server.DateCurrent + Server.DateUTC)
>>>>> Print "From Mem: "&   Float@(Data)
>>>>> Print "Reversed: "&   Float@(Convert.Reverse(Data))
>>>>
>>>> Your code cannot work : Data receives a Float ( Read #Mem As Float ),
>>>> and later is used as a Pointer ( Float@(Data) ).
>>>
>>> Please provide some real code that I can compile!
>>
>> I put together a small project using the same variables, declarations,
>> assignments, etc., as the actual program. Interestingly, sometimes the
>> "From Mem" and "Reversed" results are the same, other times they are
>> different. They also seem to cycle between the same values instead of
>> changing based on the current time. Something really weird's going on.
>> Hopefully I'm just being an idiot and there's a simple solution.
>
> Note that if you write to #Mem, the #Mem file pointer (which is the memory
> address) increases, so the next Read is done eight bytes after!

Ahhh, it was something stupid. I should have known better. I added "Seek 
#Mem, 0" and it now works properly. Interestingly I no longer need to 
reverse the string on the recipient's end as I was doing previously. 
Thanks for the help.

-- 
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271





More information about the User mailing list