[Gambas-user] gb3: writing variables to a string using a memory stream and pointer
Benoît Minisini
gambas at ...1...
Sun Sep 11 17:34:00 CEST 2011
> My code looks like this:
>
> ' For writing outgoing UDP data to memory.
> Public data As String
> Public mem As Stream
>
> ' Create data string for outgoing transaction queue.
> data = Space(8)
> mem = Memory VarPtr(data) For Write
> mem.Begin
> Write #mem, (Server.DateCurrent + Server.DateUTC) As Float
> mem.Send
> Print data
>
> It throws signal 11 on the Print statement.
>
> I have two questions. First is this the correct way to write one or more
> variables to a string in memory, and second what's up with the signal
> 11? I'm using revision 4094 and will update to the newest revision in a
> moment.
Signal 11 means that you try to write at a forbidden memory address.
At first sight, you should be able to write to VarPtr(data)... *BUT* you must
not.
Because all Gambas strings are READ-ONLY, because they can be shared.
So you must use Alloc() and Free() (like in C) to allocate the memory you want
to write to.
Regards,
--
Benoît Minisini
More information about the User
mailing list