From bbe214128b6f7cb4e57fcda7adc3205ec9ec66cb Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 30 Jun 2019 18:35:20 -0400 Subject: allow manual memory management for types frequently used in messaging --- bench_network/main.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'bench_network') diff --git a/bench_network/main.go b/bench_network/main.go index 842fed2..fc46ea0 100644 --- a/bench_network/main.go +++ b/bench_network/main.go @@ -22,12 +22,15 @@ const ( MSG_OPCODE_BYTES salticidae.Opcode = iota ) -func msgBytesSerialize(size int) salticidae.Msg { - serialized := salticidae.NewDataStream() +func msgBytesSerialize(size int) (res salticidae.Msg) { + serialized := salticidae.NewDataStream(false) serialized.PutU32(salticidae.ToLittleEndianU32(uint32(size))) serialized.PutData(make([]byte, size)) - return salticidae.NewMsgMovedFromByteArray( - MSG_OPCODE_BYTES, salticidae.NewByteArrayMovedFromDataStream(serialized)) + ba := salticidae.NewByteArrayMovedFromDataStream(serialized, false) + serialized.Free() + res = salticidae.NewMsgMovedFromByteArray(MSG_OPCODE_BYTES, ba, false) + ba.Free() + return } func checkError(err *salticidae.Error) { @@ -72,7 +75,9 @@ func onTerm(_ C.int, _ unsafe.Pointer) { func onTrigger(_ *C.threadcall_handle_t, userdata unsafe.Pointer) { id := *(*int)(userdata) mynet := &mynets[id] - mynet.net.SendMsg(msgBytesSerialize(256), mynet.conn) + payload := msgBytesSerialize(256) + mynet.net.SendMsg(payload, mynet.conn) + payload.Free() if !mynet.conn.IsTerminated() { mynet.tcall.AsyncCall(salticidae.ThreadCallCallback(C.onTrigger), userdata) } -- cgit v1.2.3-70-g09d2