What's syntax or feature you would like to create for VB or .net ?
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
# Pointer
One of syntax I don't think it going to be apply to VB.net by MS is `pointer` , I half agree and half disagree with this decision because it's hard to guarantee its safety but it also give you a lot of performance if you use it right.
This is latest version I created and use.
https://github.com/RevensofT/STD
## ref(Of T) type
A new type for unsafe pointer, it's value of reference type aka it's value type but invoke by method as reference type.
## Constructor via extension method
### ref(Of T)(ByRef Input As T) As ref(Of T)
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.
```vb
Dim Base = {1, 2, 3, 4, 5}
Dim A = Base(0).ref
```
## Property
### value As T
Get and set value via pointer, simply ldobj and stobj.
```vb
A.value = 8
```
### Default Readonly index(Offset As Int64) As ref(Of T)
Move current pointer to other index offset of `T` unit.
```vb
Dim Base = {1, 2, 3, 4, 5}
Dim A = Base(1).ref
Dim B = A(1)
'A.value is 2
'B.value is 3
```
### Readonly range(Destination As ref(Of T)) As Int64
Measure distance between this pointer and `Destination` pointer in `T` unit.
```vb
Dim Base = {1, 2, 3, 4, 5}
Dim A = Base(1).ref
Dim B = Base(4).ref
'B.range(A) is 4
```
### Shared size As UInt64
Get size of `T` unit.
```vb
'ref(Of Int64).size is 8
'ref(Of Int32).size is 4
```
## Method
### Sub copy(Destination As ref(Of T), Length As UInt64)
Copy data from this pointer to Destination pointer.
```vb
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}
```
### Function change(Of V)() As ref(Of V)
Get new pointer of `V` type point at the same address as this pointer.
```vb
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}
```
# Unsafe cast type
Other thing I'm would love to have but hate to live with is `unsafe cast` , DirectCast and CType do a good job to keep a code safe but also give me no other way to cast some type I know it fine like cast base type to inherit that only add method without touch field.
### as(Of T, V)(Input As T) As V
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.
```vb
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
```
# Stack frame allocate memory
Only 2 way I can think to create it until now is create a local var of structure and reference it via pointer to simulate is like `stack alloc` and other way is `localloc` aka `stack alloc` via method and use it on other argument method delegate, first one is uneasy to create a large alloc and second one request 2 extra stack frame to do it, cost over performance.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.