-
-
Save modularbot/a6c43d73ec9532fb8a7fcf258f3c02ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias dtype = DType.float64 | |
struct MyStruct: | |
var ptr : DTypePointer[dtype] | |
var len:Int | |
fn __init__(inout self, len:Int): | |
self.len = len | |
self.ptr = DTypePointer[dtype].alloc(len) | |
fn __copyinit__(inout self, borrowed existing:Self): | |
print("> __copyinit__()") | |
self.len = existing.len | |
self.ptr = DTypePointer[dtype].alloc(self.len) | |
for i in range(self.len): | |
self.ptr[i] = existing.ptr[i] | |
fn __moveinit__(inout self, owned existing:Self): | |
print("> __moveinit__()") | |
self.len = existing.len | |
self.ptr = existing.ptr | |
fn __del__(owned self): | |
print("> __del__()") | |
self.ptr.free() | |
fn main(): | |
print("$ var a = MyStruct(10)") | |
var a = MyStruct(10) | |
print("$ a.ptr[0] = 37") | |
a.ptr[0] = 37 | |
print("$ print(a.ptr[0])") | |
print(a.ptr[0]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment