Jump to content

How to declare dynamic memory by new in systemC


Recommended Posts

Hello everyone,

I am trying to design memory in systemC  , first i tried with regular array it worked perfectly.

sc_uint<32> mem[MEMORY_DEPTH]; bur storing higher no of bytes, regular array is not working.


thats why i tried with dynamic allocation of memory by new keyword.

int *mem= new int [MEMORY_DEPTH];

but it produces following errors, can anyone please help me, how to solve this problem.

error: 'new' cannot appear in a constant-expression
error: ISO C++ forbids initialization of member 'mem' [-fpermissive]
error: making 'mem' static [-fpermissive]
error: invalid in-class initialization of static data member of non-integral type 'int*'


thanks and regards




Link to comment
Share on other sites

Actually using new is not recommended at all. You should do something like:

std::array<sc_dt::sc_uint<32>, MEMORY_DEPTH> mem;

or (C++11):

std::vector<sc_dt::sc_uint<32>> mem{MEMORY_DEPTH};

As far as I can see you try to initialize mem in-class (during declaration) and this is not allowed in C++. You can do this only in the constructor. And if you need to use new, don't forget to delete.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...