realbasic-nug
[Top] [All Lists]

Re: Turning Integers into MemoryBlocks?

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Turning Integers into MemoryBlocks?
From: Jonathan Johnson <jonj at realsoftware dot com>
Date: Tue, 31 Aug 2004 10:00:11 -0500
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <86BE5A62-FB59-11D8-9A45-000393C0FE92 at 006 dot co dot uk> <FF5157ED-FB5B-11D8-B23F-000A95880024 at bitjuggler dot com> <05DA9740-FB5D-11D8-9A45-000393C0FE92 at 006 dot co dot uk>

On Aug 31, 2004, at 9:49 AM, Charlie Boisseau wrote:

On 31 Aug 2004, at 15:42, Thomas Reed wrote:

What routine are you calling, and what does your code look like? I have a number of callback routines that are defined to return MemoryBlocks, and they work just fine. I'd be extremely surprised if you couldn't use MemoryBlock as a parameter type in a callback as well.

I looked at Jon's previous post as he suggested. I found that i was missing the line mb = mb.Ptr(0), but these make the MemoryBlock empty.

Not exactly. The data is what you asked for, but REALbasic has no knowledge of the pointer returned when you access mb.Ptr(). That memory is owned by another process. So, mb.Size will return 0. You need to know the size of the data structures you're trying to access, and you can still accomplish it.

A few things to note:

Sub got_packet(Args As Integer, Header As Integer, Packet As Integer)
   Dim head As New MemoryBlock(1500)
   Dim pkt As New MemoryBlock(1500)
        ...
   head.long(0) = Header
   pkt.long(0) = Packet
   head = head.Ptr(0)
   pkt = pkt.Ptr(0)

You're creating 1500 byte memoryblocks, then using the first 4 bytes. Next, you're throwing away the entire memoryblock by replacing it with the return value from .Ptr(). The memoryblocks only need to be 4 bytes.

   head_str = head.StringValue(0, head.Size)
   pkt_str = pkt.StringValue(0, pkt.Size)

Assuming that 1500 is the size you want, you should pass 1500 here instead of head.Size and pkt.Size. In the process of getting a new memoryblock from .Ptr(), REALbasic cannot guess what size the returned pointer really is, so you'll be seeing 0 there.

HTH,
Jon


--
Jonathan Johnson
Testing Department
REAL Software, Inc.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>