What am I able to cast to ^Void?

Hey guys,

when i want to cast a tuple of (Tkey, TValue) to ^Void, it tells me, that it cant cast this.

Why??

I’d say, In contrary to C++, void is not just an untyped type under .NET.

That means, that im not able to get a empty pointer to a record/class?

Thats by Definition pure crap!

How about null for nullable types? Sorry, meant nil in terms of Oxygene.

No, that’s not crap, it’s part of the .NET CLR. And this makes sense as Oxygene started as a .NET compiler. In fact, under .NET you cannot cast anything to void. There is a type void but it’s used by reflection.

What platform? On .NET or Java, says no, you can’t just get the address of something. I wouldn’t call that “pure crap”.

2 Likes

Ahh sry, Platform is: Island ^^

What would you do with a pointer to a tuple?

the Island - MemoryStream wants it and i Need to write some data in Memory

What my soluion was, calls memstr.Write(…) 2 times with item1 and item2

 f_buffer.Write(^Void(pair.item1), sizeOf(pair.item1) * 1);
 f_buffer.Write(^Void(pair.item2), sizeOf(pair.item2) * 1);

But i still want to know, does this work on Island or not?

Not like that. It would write a pointer which would be useless, you’d want:

 f_buffer.Write(@pair.item1, sizeOf(pair.item1) * 1);
 f_buffer.Write(@pair.item2, sizeOf(pair.item2) * 1);

Ah, I have overseen the ^ in front of the void.

@shpend_hoti Wouldn’t it be a bit wiser to not call something crap before really understanding the underlying technique?

I tried that, and i get an error:

"Error (E406) No overloaded method “Write” with these parameters on type “MemoryStream”, best matching overload is “method Write(buf: ^Void; Count: Int32): Int32”

Because i want to write a T1 and T2 (generic Arguments)

pair.item1 = typeof(T1)
pair.item2 = typeof(T2) //-- Just for notice

In General, would you write a Little example, how do i read/write exactly a tuple from/to memorystream, i am pretty confused about that^^

When generics are involved it gets a little trickier. a tuple of Int, Int would be fine, but what if it’s a tuple of string, string? You can’t just write a string like that, it would write the pointer, which is useless. Generally to do this you’d use a serializer to a well known format.

where can i get those serializers?



I know what serialization is about, i was actually asking where i can get some good serializers for
[ISLAND: Oxygene]

But i think, i Need to do this on my own…

The Problem is, when i want to read even a normal integer out of the memorystream, it gives me 0 back, instead of the total size ??

What am i doing wrong:

f_buffer.Write(@number, sizeof(number) * 1);
var res: int32 := f_buffer.Read(@number, sizeof(number) * 1);  //gives always 0 back

Thats because you write, which moves the position by 4, then read from there, which is at the end of the stream.

Thanks a lot, carlo, but i am wondering, why am i able to write strings?

see the Code:

var data: Somerec;
  data.A := 'Z';
  data.B := 'H';
  data.C := 'C';
  data.D := 2000;
  data.E := 3000;
  data.F := DateTime.Now;
  data.G := 'text';

  var d: MemoryStream := new MemoryStream();
              
  d.Write(@data, sizeOf(data) * 1);

  d.Position := 0;

  var res : Somerec;

  d.Read(@res, sizeOf(data)* 1);
  writeLn(res.A);
  writeLn(res.G);  //res.G => string
        
  readLn;

Because you’re in the same address space. It’s writing a pointer (4 or 8 bytes), it just happens that the stuff you’re reading is stil at the same position.