Skip to content

Commit

Permalink
emscripten web-fc-solve: consolidate memory allocations [malloc()/etc.]
Browse files Browse the repository at this point in the history
  • Loading branch information
shlomif committed Apr 8, 2024
1 parent 14d8396 commit 1d09af4
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions fc-solve/site/wml/src/ts/web-fc-solve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export class FC_Solve {
private _pre_expand_states_and_moves_seq: any;
private _post_expand_states_and_moves_seq: any;
private _args_buffer: number;
private _last_arg_ptr_buffer: number;
private _move_buffer: number;
private _move_string_buffer: number;
private _state_string_buffer: number;
Expand Down Expand Up @@ -747,13 +748,15 @@ export class FC_Solve {
const _move_string_buffer_size: number = 200;
const _move_buffer_size: number = 64;
const _args_buffer_size: number = 4 * 2;
const _last_arg_ptr_buffer_size: number = 4;
const _total_buffer_size: number =
_state_string_buffer_size +
_move_string_buffer_size +
_move_buffer_size +
_read_from_file_str_ptr_size +
_arg_str_ptr_size +
_args_buffer_size;
_args_buffer_size +
_last_arg_ptr_buffer_size;
that._state_string_buffer = that.module_wrapper.alloc_wrap(
_total_buffer_size,
"state+move string buffer",
Expand All @@ -771,6 +774,7 @@ export class FC_Solve {
that._arg_str_ptr =
that._read_from_file_str_ptr + _read_from_file_str_ptr_size;
that._args_buffer = that._arg_str_ptr + _arg_str_ptr_size;
that._last_arg_ptr_buffer = that._args_buffer + _args_buffer_size;

if (that.string_params) {
const error_string_ptr_buf = that.module_wrapper.alloc_wrap(
Expand Down Expand Up @@ -817,11 +821,7 @@ export class FC_Solve {
ptr_type,
);

const last_arg_ptr = that.module_wrapper.alloc_wrap(
4,
"last_arg_ptr",
"cherry",
);
const last_arg_ptr: number = that._last_arg_ptr_buffer;

// Input the file to the solver.
const args_ret_code =
Expand All @@ -839,8 +839,6 @@ export class FC_Solve {
0,
);

that.module_wrapper.c_free(last_arg_ptr);

const error_string_ptr = that.module_wrapper.Module.getValue(
error_string_ptr_buf,
ptr_type,
Expand Down

0 comments on commit 1d09af4

Please sign in to comment.