aboutsummaryrefslogtreecommitdiff
path: root/bench_network
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-06-30 18:35:20 -0400
committerDeterminant <[email protected]>2019-06-30 18:35:20 -0400
commitbbe214128b6f7cb4e57fcda7adc3205ec9ec66cb (patch)
tree67563de5f0ab2bd9cef29e5ed7efb25398f6219c /bench_network
parentd247c437f396709f62eadaf863b8a552d7142fc7 (diff)
allow manual memory management for types frequently used in messaging
Diffstat (limited to 'bench_network')
-rw-r--r--bench_network/main.go15
1 files changed, 10 insertions, 5 deletions
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)
}