Classic Memoryblock to xojo.core Memoryblock conversion?

The xojo compiler is throwing the following exception when dealing with an array of data in the new framework’s HTTPSocket provided by the classic Web edition’s file uploader:

“Parameter “Data” expects xojo.core.memoryblock but this is a class memoryblock”

Is there any way to efficiently cast a classic memoryblock to a new framework memoryblock?

Thanks,

Eric

Dim mbClassic As New Global.MemoryBlock(4) mbClassic.Int32Value(0) = 1234 Dim mbXojo As New Xojo.Core.MemoryBlock(mbClassic) Dim value As Integer = mbXojo.Int32Value(0)

Thanks for this, apologies for posting in the wrong area!

[quote=192538:@Eli Ott]Dim mbClassic As New Global.MemoryBlock(4) mbClassic.Int32Value(0) = 1234 Dim mbXojo As New Xojo.Core.MemoryBlock(mbClassic) Dim value As Integer = mbXojo.Int32Value(0)[/quote]

This should be done instead, because it’ll preserve the size information. The classic MemoryBlock’s size should be passed into the new MemoryBlock’s constructor as the second argument. It also doesn’t retain the original MemoryBlock’s endianness.

However, going this route makes the new Xojo.Core.MemoryBlock refer to a pointer owned by the classic MemoryBlock. When that classic MemoryBlock goes away, the new Xojo.Core.MemoryBlock is basically invalid and using it will crash. That’s generally not what you want, so you would have to make a byte-by-byte copy of the old MemoryBlock into a new Xojo.Core.MemoryBlock.

I think the new Xojo.Core.MemoryBlock class needs a constructor that says “copy the bytes”, but unfortunately one doesn’t exist yet.

Admins can move threads, so I’ve put this in general.

Thanks Joe, I put in the size as a second parameter. The pointing method should be ideal for my app (which deals with one element of uploaded data at a time btw).

I can’t determine the endianness of the Web file upload data. Is this inherited as a default from somewhere and if so, will the new framework memoryblock inherit the same default endianness?

Can’t you just use the LittleEndian property on MemoryBlock?

The docos say WebUploadedFile.Data is a string but the compiler seems to regard it as a classic memoryblock.

I guess classic strings don’t have endianess issues being only one byte per Char? If the new and classic memory blocks default to the same there shouldn’t be an issue for what I want to do. Is this guaranteed by the API?

I was unaware that memory blocks could be cast to other types.
Have I understood this?
If I have a structure and a memory block that reflects it I can cast the memory block to the structure and vise versa?
Does this apply to classes as well?

I would really appreciate if the framework could allow some easier conversion.
e.g. have a method to return the memoryblock in other format on each with referencing the same bytes and ref counting the other object as parent.

And if you need me to switch a compile option differently, please tell me.

So far I enabled FTS3/FTS4, RTREE, Column Metadata, Thread Safe and Soundex.

[quote=192723:@Brian O’Brien]If I have a structure and a memory block that reflects it I can cast the memory block to the structure and vise versa?
Does this apply to classes as well?[/quote]
You have access to the pointer pointing to a memory block:

Dim p As Ptr = aMemoryBlockInstance

But you don’t have access to a pointer pointing to a Structure, Class, or Object as far as I know.

[quote=192748:@Eli Ott]You have access to the pointer pointing to a memory block:

Dim p As Ptr = aMemoryBlockInstance

This is specifically because MemoryBlock has an Operator_Convert to pointer.

[quote=192723:@Brian O’Brien]I was unaware that memory blocks could be cast to other types.
Have I understood this? [/quote]
The example given is not casting. It is using a Constructor to create a new object that points to the original memoryblock.

is there a way get the ptr from a xojo.core.memoryblock as we used to have it form the classic framework or do I need to cast it to the classic memoryblock (but this seems unproductive). ?

#edit:
found it.
xojo.core.memoryblock.data gets the ptr.

I guess I need to dig more inot the new framework. Too much changes.

http://developer.xojo.com/xojo-core-memoryblock$PtrValue ?

MemoryBlock.Data is correct. PtrValue is for getting a pointer value stored at offset nnn.

Ah OK. Sort of a modern Peek :wink:

Thank you.