sim-c icon indicating copy to clipboard operation
sim-c copied to clipboard

[FEATURE] Dynamic memory allocation

Open frankhart2018 opened this issue 5 years ago • 13 comments

Is your feature request related to a problem? Please describe. Dynamic memory allocation in simC.

Describe the solution you'd like Open ended, come up with an intuitive syntax.

Note: Discuss syntax with a maintainer before implementing.

frankhart2018 avatar Sep 02 '20 17:09 frankhart2018

@frankhart2018 Hi I want to work upon this issue. will use malloc for this purpose..

Gaurav7888 avatar Dec 05 '20 02:12 Gaurav7888

@Gaurav7888 please mention the syntax here, once that is approved I or any other maintainer can assign you to this.

frankhart2018 avatar Dec 05 '20 15:12 frankhart2018

Like (pointer type ) malloc(sizeof() ) This is in general syntax gonna use .

Gaurav7888 avatar Dec 05 '20 15:12 Gaurav7888

DMA includes allocating, reallocating, and deleting.

@Aayush-99 @PranshulDobriyal

frankhart2018 avatar Dec 05 '20 15:12 frankhart2018

free() could be used for deletion I just checked out there is something called realloc() for this purpose , i will learn how to use it and apply to solve this issue. @frankhart2018

Gaurav7888 avatar Dec 05 '20 15:12 Gaurav7888

@Gaurav7888 What syntax do you propose for the same in SimC ?

PranshulDobriyal avatar Dec 07 '20 13:12 PranshulDobriyal

@PranshulDobriyal cpython have some functions to do abv things .

Gaurav7888 avatar Dec 07 '20 13:12 Gaurav7888

@Gaurav7888 Yes that will explain the backend of the desired functions, but what front-end (syntax in simC) do you propose. For ex- front-end (SimC code) -> print("hello world!!") back-end - various functions that generate the corresponding C code -> printf("hello world!!");

PranshulDobriyal avatar Dec 07 '20 13:12 PranshulDobriyal

@Gaurav7888 They are asking for something like:

Example of Sim-C allocating memory:

SimC code:

var i = new int
var j = new int[10]

Generated C code:

int* i = malloc(sizeof(int)); 
int* j = malloc(10*sizeof(int)); 

It's like SimC will interpreter the command.

Math-O5 avatar Dec 09 '20 20:12 Math-O5

@frankhart2018 Sim-C should predict the type of the variable? If so, it's change a lot of expected code.

A example.

SimC code:

var i = new var
var j = new var[10]

Math-O5 avatar Dec 09 '20 20:12 Math-O5

What do we need dynamic memory allocation for other than variable length arrays?

victorjzsun avatar Jan 01 '21 03:01 victorjzsun

Can you start a discussion for this @victorjzsun.

frankhart2018 avatar Jan 01 '21 07:01 frankhart2018

Created a discussion here

victorjzsun avatar Jan 01 '21 20:01 victorjzsun