If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Error in user guide
3 posts
• Page 1 of 1
Error in user guide
Hi folks.
I'm kind of surprised about these lines in flowstone user guide, and also with provided helper functions.
if we use a new [] we need to use delete[]. Could be serious memory issue, if you leak an array of size N at each function call...
I'm kind of surprised about these lines in flowstone user guide, and also with provided helper functions.
if we use a new [] we need to use delete[]. Could be serious memory issue, if you leak an array of size N at each function call...
- Code: Select all
// Delete previous array and reset pOut entry
if( pOut[x] )
{
delete *((int**)&pOut[x]);
pOut[x] = 0;
}
// Create new array (assume we have declared 'length' – add 1 for size at front)
int* array = new int[length+1];
- francoisreme
- Posts: 29
- Joined: Wed Feb 15, 2017 4:01 pm
Re: Error in user guide
Unfortunately, the code examples in the FlowStone documentation and default toolbox items are often of a pretty poor standard. You're quite right of course, the C++ standard says that new[] -> delete is "undefined behaviour". In most compilers, it does work without leaking memory so long as the array contains only POD data types, as they have no destructors to call - so it's fortunate that the DLL API types are all POD (string arrays contains C-style strings which have to be freed manually)!
I've seen other coders do this for POD arrays, especially if they're regular C coders who haven't used C++ much. The compiler will optimise away destructor calls if they're not required, so there's no clever "hacky" reason to do it - it's really easy to get caught out by it if you change the array to contain objects, and it can get beginners into bad habits!
I've seen other coders do this for POD arrays, especially if they're regular C coders who haven't used C++ much. The compiler will optimise away destructor calls if they're not required, so there's no clever "hacky" reason to do it - it's really easy to get caught out by it if you change the array to contain objects, and it can get beginners into bad habits!
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: Error in user guide
Didn't event know that (POD types) !
- francoisreme
- Posts: 29
- Joined: Wed Feb 15, 2017 4:01 pm
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 80 guests