MCPcopy Index your code
hub / github.com/yuin/gopher-lua / SetMx

Method SetMx

state.go:2242–2258  ·  view source on GitHub ↗

* }}} */ * GopherLua original APIs {{{ */ Set maximum memory size. This function can only be called from the main thread.

(mx int)

Source from the content-addressed store, hash-verified

2240
2241// Set maximum memory size. This function can only be called from the main thread.
2242func (ls *LState) SetMx(mx int) {
2243 if ls.Parent != nil {
2244 ls.RaiseError("sub threads are not allowed to set a memory limit")
2245 }
2246 go func() {
2247 limit := uint64(mx * 1024 * 1024) //MB
2248 var s runtime.MemStats
2249 for atomic.LoadInt32(&ls.stop) == 0 {
2250 runtime.ReadMemStats(&s)
2251 if s.Alloc >= limit {
2252 fmt.Println("out of memory")
2253 os.Exit(3)
2254 }
2255 time.Sleep(100 * time.Millisecond)
2256 }
2257 }()
2258}
2259
2260// SetContext set a context ctx to this LState. The provided ctx must be non-nil.
2261func (ls *LState) SetContext(ctx context.Context) {

Callers 2

testScriptDirFunction · 0.45
mainAuxFunction · 0.45

Calls 1

RaiseErrorMethod · 0.95

Tested by 1

testScriptDirFunction · 0.36