paladin-t / my_basic

A lightweight BASIC interpreter written in standard C in dual files. Aims to be embeddable, extendable and portable.
http://paladin-t.github.io/my_basic/
MIT License
508 stars 118 forks source link

Obtain memory allocation programatically? (NOT ISSUE) #66

Closed invpe closed 2 years ago

invpe commented 2 years ago

Having

PRINT MEM in the script file working, is there any way to obtain the same information in my native application by calling a function of MyBasic lib ?

paladin-t commented 2 years ago

MY-BASIC uses a _mb_allocated variable to count allocations in "my_basic.c", so that it could tell footprint with the MEM command. But it doesn't know allocations outside the core.

I suggest to use similar method in your native program, e.g. write dedicated allocate/free functions to manage all the memory operations. Moreover, you can also consider using a memory pool lib, which often offers more than allocation count in practice.

invpe commented 2 years ago

@paladin-t thanks, i was looking for a function that will return memory allocation of mybasic. This is to see the memory footprint of the script before calling any dispose/close functions of the interpreter.

Something along these lines:


iRetCode = mb_run(bas, true);

// Grab memory consumption before closing things
iMemAllocated = mb_mem(bas);
printf("Memory consumed by mybasic %ib\n",iMemAllocated);

mb_close(&bas);
mb_dispose();
paladin-t commented 2 years ago

Ah, sry I didn't get that.

Closing this.