Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
ygopro-core
Commits
d5a0b5b7
Commit
d5a0b5b7
authored
Jul 12, 2025
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve lua memtracker
parent
669f3410
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
11 deletions
+9
-11
LuaMemTracker.cpp
LuaMemTracker.cpp
+7
-2
LuaMemTracker.h
LuaMemTracker.h
+1
-1
interpreter.cpp
interpreter.cpp
+1
-8
No files found.
LuaMemTracker.cpp
View file @
d5a0b5b7
#include "LuaMemTracker.h"
#include <lauxlib.h>
LuaMemTracker
::
LuaMemTracker
(
size_t
mem_limit
)
:
limit
(
mem_limit
)
{
lua_State
*
tmp_L
=
luaL_newstate
();
// get default alloc
real_alloc
=
lua_getallocf
(
tmp_L
,
&
real_ud
);
lua_close
(
tmp_L
);
LuaMemTracker
::
LuaMemTracker
(
lua_Alloc
alloc_func
,
void
*
ud
,
size_t
mem_limit
)
:
real_alloc
(
alloc_func
),
real_ud
(
ud
),
limit
(
mem_limit
)
{
#ifdef YGOPRO_LOG_LUA_MEMORY_SIZE
time_t
now
=
time
(
nullptr
);
char
filename
[
64
];
...
...
LuaMemTracker.h
View file @
d5a0b5b7
...
...
@@ -12,7 +12,7 @@
class
LuaMemTracker
{
public:
LuaMemTracker
(
lua_Alloc
real_alloc
,
void
*
real_ud
,
size_t
mem_limit
=
0
);
LuaMemTracker
(
size_t
mem_limit
=
0
);
~
LuaMemTracker
();
static
void
*
AllocThunk
(
void
*
ud
,
void
*
ptr
,
size_t
osize
,
size_t
nsize
);
void
*
Alloc
(
void
*
ptr
,
size_t
osize
,
size_t
nsize
);
...
...
interpreter.cpp
View file @
d5a0b5b7
...
...
@@ -15,14 +15,7 @@
#include "interpreter.h"
interpreter
::
interpreter
(
duel
*
pd
)
:
coroutines
(
256
)
{
lua_State
*
tmp_L
=
luaL_newstate
();
// 只是为了拿默认 alloc
lua_Alloc
raw_alloc
;
void
*
raw_ud
;
raw_alloc
=
lua_getallocf
(
tmp_L
,
&
raw_ud
);
lua_close
(
tmp_L
);
mem_tracker
=
new
LuaMemTracker
(
raw_alloc
,
raw_ud
,
YGOPRO_LUA_MEMORY_SIZE
);
mem_tracker
=
new
LuaMemTracker
(
YGOPRO_LUA_MEMORY_SIZE
);
lua_state
=
lua_newstate
(
LuaMemTracker
::
AllocThunk
,
mem_tracker
);
current_state
=
lua_state
;
pduel
=
pd
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment