Simple library to help you access to data in memory with less restain from C# or VB language limited.
- 3 extension method
- ref(of T) as pointer
A new type for unsafe pointer, it's value of reference type aka it's value type but invoke by method as reference type.
Get and set value via pointer.
A.value = 8
Move current pointer to other index offset of T
unit.
Dim Base = {1, 2, 3, 4, 5}
Dim A = Base(1).ref
Dim B = A(1)
'A.value is 2
'B.value is 3
Measure distance between this pointer and Destination
pointer in T
unit.
Dim Base = {1, 2, 3, 4, 5}
Dim A = Base(1).ref
Dim B = Base(4).ref
'B.range(A) is 4
Get size of T
unit.
'ref(Of Int64).size is 8
'ref(Of Int32).size is 4
Copy data from this pointer to Destination pointer.
Dim Base = {1, 2, 3, 4, 5}
Dim A = Base(0).ref
Dim B = Base(3).ref
A.copy(B, 2)
'Base is {1, 2, 3, 1, 2}
Get new pointer of V
type point at the same address as this pointer.
Dim Base = {1, 2, 3, 4, 5}
Dim A = Base(0).ref
Dim B = A.change(Of Int64)
B.value = 0
'Base is {0, 0, 3, 4, 5}
Create pointer from target, field of class and element of array are most safe pointer you can create without any concern, pointer of local var and value type should be use within their life cycle.
Dim Base = {1, 2, 3, 4, 5}
Dim A = Base(0).ref
Same as previous but you can change its type to other on create.
It's MemberwiseClone
for duplicate a reference type object.
Dim Base = {1, 2, 3, 4, 5}
Dim A = Base.mirror
A(0) = 56
'Base(0) still be 1
Unsafe cast type on .net, you can cast object to any type, doesn't matter if it ref type or val type, highly cause an error if you don't know what are you doing.
Dim Base = {1, 2, 3, 4, 5}
Dim A = Base.as(Of ref(Of Intptr))
'A(1).change(UInt64) is 5, aka Base.Length
'A(2).change(Int32) is Base(0).ref
Any local var always end life cycle with method, when extied method, any pointer refer to those local var will be volatile.
Dim Base = {1, 2, 3, 4, 5}
Dim A = Base.ref
Dim B = Base(0).ref
Return A
'A is refer to Base not Int32() so when exited current method, this refer going to be volatile soon.
'However if return B instead, it won't be volatile because it refer to a part of Int32().
Mismatch data on cast type won't be report as an error on worst case when you use 'as' method, you will get corrupt data instead; cast on interface type can be done but require an implement method match to original data you refer to, invoke any method hasn't implement will cause an error.