CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Sun Sep 15, 2019 8:45 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Dynamic memory
PostPosted: Tue Oct 11, 2011 11:30 am 
Offline

Joined: Thu Jul 01, 2010 11:19 am
Posts: 30
Good morning,

I would like to create a dynamic FIFO. I am using __NEW and __DELETE but when I am compiling the application, I always get this error:

typify code ...
[ERROR] (Line 2, Column 1 (Impl)): No memory for dynamic object creation defined for application
[ERROR] (Line 2, Column 1 (Impl)): A Functionblock or Structure needs the attribute '{attribute'enable_dynamic_creation'}' to be created with __NEW

I am trying to paste this atribute but I do not know where exactly {atribute 'enable_dynamic_creation'}.

Can anybody help me?

Thanks in advance!


Top
   
 Post subject: Re: Dynamic memory
PostPosted: Tue Oct 11, 2011 3:25 pm 
Offline

Joined: Thu Aug 04, 2011 11:16 am
Posts: 86
Hi,
you have to enable the usage of dynamic memory allocation.

- Right click on the application
- properties
- Dynamic memory settings
- Enable "Use dynamic memory allocation" and set the maximum size of memory


Top
   
 Post subject: Re: Dynamic memory
PostPosted: Tue Oct 11, 2011 3:49 pm 
Offline

Joined: Thu Jul 01, 2010 11:19 am
Posts: 30
Thanks a lot!


Top
   
 Post subject: Re: Dynamic memory
PostPosted: Tue Oct 25, 2011 9:07 am 
Offline

Joined: Tue Aug 30, 2011 9:47 pm
Posts: 13
I've tried using __NEW and it works.

As I have to set the maximum size of dynamically allocated memory (e.g. 1000 bytes), what is the real benefit of using dynamical allocation (__NEW) ?

In case of a FIFO you have the maximum memory size as a limit (e.g. 1000 bytes). So there's no advantage compared to an static array with 1000 bytes.

Can anyone tell me an example where the dynamic memory has an advantage over static variables?

I thought about handling different data types, but it didn't work because you have to set the data type in the declaration (e.g. pNumber : Pointer to XY).
In case of your FIFO I don't think the dynamic memory has an advantage over an static array.
I guess you've realised the FIFO as an array like in the V3 help (see __NEW entry of help file).

Solution 1:
You create a big "array" and you always stay within its bounds. -> Same behaviour like static array.

Solution 2:
You create an "array" with only one element. As the bounds of an "array" in the dynamic memory are only fictive, you never change the size of this "array", but use more than one element (e.g. pArray[9] := z). -> Very dangerous to use memory you have not explicitly allocated (could work if you use only this array and nothing else within the dynamic memory?).

Solution 3:
Everytime a new element is put into the FIFO or taken out of it, you create a new "array" with size -1/+1, copy all elements and delete the old one. -> Much work and copying is necessary which is probably slower than a static array. And as you have the maximum dynamic memory size as maximum bound, you could also use a static array of the same size.

PS: I have set "array" in quotes because it is declared as a pointer but used like an array with fictive bounds.


Top
   
 Post subject: Re: Dynamic memory
PostPosted: Mon Nov 07, 2011 3:48 pm 
Offline

Joined: Thu Jul 01, 2010 11:19 am
Posts: 30
Thanks for your support!


Top
   
 Post subject: Re: Dynamic memory
PostPosted: Fri Nov 09, 2012 4:13 pm 
Offline

Joined: Mon Oct 01, 2012 8:33 am
Posts: 53
When is it required to de-allocate memory using _DELETE? Is there any documentation or discussion about doing proper cleanup. I am particularly interested about restart, online code changes, etc and correct usage of FB_exit, FB_reinit, and FB_init. Tanks

@Patmo1: Not all instances require the same list length (same array size). If the array is dynamically allocated then it can be appropriately sized for each instance. You would just have an init method or a size property to do the sizing (i.g. Fifo.Init(size) or Fifo.Size := size).


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited