More followup. So I played with MutableMemoryBlock:
[code]Dim mb as new Xojo.Core.MutableMemoryBlock( 5e9 )
Dim tSize as integer = mb.size
dim p as Ptr = mb.Data
fastFillPtr8(p, 127, tSize)
b = checkPtr8values(p, 127, tSize)
for j as integer = tSize-1 DownTo 0
p.UInt8(j) = 127
next
[/code]
Here the size is reported correctly, my C plugin fills the bytes, and checks the values correctly (even for ridiculously large blocks of 20e9 bytes). However, the XOJO loop crashes after a few seconds (see the crash log at the end). If I reduce the size to 2e9, the xojo loop completes correctly and all bytes verify.
So MutableMemoryBlock allocates correctly, returns the correct size, returns a valid Ptr in mb.Data, but there is an addressing problem also for large MutableMemoryBlocks.
As an aside, my C plugin fills 2e9 bytes in 0.1 seconds (in fairness, that’s the second time around, the first time it takes about 10x longer, probably the memory manager is mapping requested pages into RAM or something) vs the xojo for-next loop that takes 52 seconds.
I did include these pragmas to give xojo its best chance:
#pragma BackgroundTasks Off
#pragma BoundsChecking Off
#pragma BreakOnExceptions Off
#pragma NilObjectChecking Off
#pragma StackOverflowChecking Off
While I expected xojo to be a bit slower than C, but 500-fold?
P.
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x000000011b125fff
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Bus error: 10
Termination Reason: Namespace SIGNAL, Code 0xa
Terminating Process: exc handler [0]
VM Regions Near 0x11b125fff:
CoreUI image data 000000011aedb000-000000011aeef000 [ 80K] rw-/rwx SM=PRV
–> mapped file 000000011aeef000-000000011b126000 [ 2268K] r–/rwx SM=COW Object_id=7e90559f
MALLOC_LARGE 000000011b126000-000000011b234000 [ 1080K] rw-/rwx SM=PRV
Application Specific Information:
Performing @selector(performClick:) from sender XOJButton 0x6040001513b0
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 memblock2Integer.debug 0x000000010e788d28 Window1.Window1.PushButton3_Action%%o<Window1.Window1>o + 3192 (/Window1:97)
1 memblock2Integer.debug 0x000000010e78ce24 Delegate.IM_Invoke%%o + 52
2 memblock2Integer.debug 0x000000010e78ce74 AddHandler.Stub.15%% + 52
3 com.apple.AppKit 0x00007fff38eb375a -[NSApplication(NSResponder) sendAction:to:from:] + 312
4 com.apple.AppKit 0x00007fff38959933 -[NSControl sendAction:to:] + 86
5 com.apple.AppKit 0x00007fff3895985b __26-[NSCell _sendActionFrom:]_block_invoke + 136
6 com.apple.AppKit 0x00007fff38959761 -[NSCell _sendActionFrom:] + 183
7 com.apple.AppKit 0x00007fff3899aa18 -[NSButtonCell _sendActionFrom:] + 97
8 com.apple.AppKit 0x00007fff38957fca -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2438
9 com.apple.AppKit 0x00007fff3899a75f -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 777
10 com.apple.AppKit 0x00007fff38956a64 -[NSControl mouseDown:] + 965
11 XojoFramework 0x000000010e91b337 0x10e843000 + 885559
12 com.apple.AppKit 0x00007fff39052959 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5891
13 com.apple.AppKit 0x00007fff3904f5b0 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2359
14 com.apple.AppKit 0x00007fff3904e85c -[NSWindow(NSEventRouting) sendEvent:] + 497
15 XojoFramework 0x000000010e926b45 0x10e843000 + 932677
16 com.apple.AppKit 0x00007fff38eaf617 -[NSApplication(NSEvent) sendEvent:] + 307
17 XojoFramework 0x000000010e9165cb 0x10e843000 + 865739
18 memblock2Integer.debug 0x000000010e6f5ec5 Application._CallFunctionWithExceptionHandling%%op + 181
19 XojoFramework 0x000000010ea96e53 CallFunctionWithExceptionHandling(void (*)()) + 262
20 XojoFramework 0x000000010e916546 0x10e843000 + 865606
21 com.apple.AppKit 0x00007fff38710d9d -[NSApplication run] + 812
22 XojoFramework 0x000000010ea9517f RuntimeRun + 40
23 memblock2Integer.debug 0x000000010e750a53 REALbasic._RuntimeRun + 19
24 memblock2Integer.debug 0x000000010e792bde _Main + 846 (/#main:87)
25 memblock2Integer.debug 0x000000010e792123 main + 19
26 libdyld.dylib 0x00007fff62b0d115 start + 1