Implement GetCacheMemory via struct abuse
This commit is contained in:
parent
c291cdbaa3
commit
a564ce4784
3
go.mod
Normal file
3
go.mod
Normal file
|
@ -0,0 +1,3 @@
|
|||
module git.gammaspectra.live/P2Pool/randomx-go-bindings
|
||||
|
||||
go 1.19
|
11
randomx.go
11
randomx.go
|
@ -1,11 +1,10 @@
|
|||
package randomx
|
||||
|
||||
//#cgo CFLAGS: -I./randomx
|
||||
//#cgo LDFLAGS: -L${SRCDIR}/lib -lrandomx
|
||||
//#cgo LDFLAGS: -lrandomx
|
||||
//#cgo LDFLAGS: -lstdc++
|
||||
//#cgo LDFLAGS: -static -static-libgcc -static-libstdc++ -lpthread -lm
|
||||
/*
|
||||
#include "randomx.h"
|
||||
#include <randomx.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
@ -109,6 +108,12 @@ func InitCache(cache *C.randomx_cache, seed []byte) {
|
|||
C.randomx_init_cache(cache, unsafe.Pointer(&seed[0]), C.size_t(len(seed)))
|
||||
}
|
||||
|
||||
func GetCacheMemory(cache *C.randomx_cache) unsafe.Pointer {
|
||||
//TODO: very unsafe. Maybe fork RandomX?
|
||||
//This abuses C.randomx_dataset having memory ptr in the same struct location as C.randomx_cache
|
||||
return C.randomx_get_dataset_memory((*C.randomx_dataset)(cache))
|
||||
}
|
||||
|
||||
func ReleaseCache(cache *C.randomx_cache) {
|
||||
C.randomx_release_cache(cache)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue