#Visual Basic Buffers
2 messages in this thread
Suppose that I need to pass an ARRAY of pointers to memory buffers…
Obviously, this would not be easy from Visual Basic. Could the following
scheme be made to work?
Build a DLL with a call to pass a buffer and return a handle to that
memory, Handle[N] = GetMemoryHandle(MyBuffer).
Declare GetMemoryHandle(Buffer As Any) As Integer
Then for each buffer call it with as above and store the returned handles
in the Integer array. Then when I wanted to pass the array of buffers,
call the same DLL (another function) and it could associate the handles
with the actual addresses. Would memory be in the SAME PLACE or would this
fail? How could I do this if not?
Any thoughts or warnings???
There is 1 Reply.
Herb –
You don't indicate the kind of memory involved or who allocated it.
In protected mode, you don't have to worry about GlobalAlloc'ed memory
moving, because you can just Lock it as you get it without worrying about
fragmenting the heap. This is the only way to get a pointer to memory in
any case: a handle to memory does no good until it's locked.
So it seems like you have two choices. Use handles to memory for the
first steps, and have the second function lock/unlock each handle as
needed.
Or, just lock each memory region as soon as you have its handle, and
keep a long integer array of pointers instead of an integer array of
handles. You could even gamble a little and assume that each region will
start at offset 0 (as it does under Win 3). This reduces the pointers to
integers again.
— Jim