Best method to delete an element in an array | Arduino Compatible Compiler for LabVIEW Discussions | Forum

Avatar
Please consider registering
guest
sp_LogInOut Log In sp_Registration Register
Register | Lost password?
Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Feed Topic RSS sp_TopicIcon
Best method to delete an element in an array
July 10, 2018
6:52 am
Avatar
Chrisreed
Member
Members
Forum Posts: 19
Member Since:
March 23, 2015
sp_UserOfflineSmall Offline

I was surprised to find out that there is no "Delete Element from Array" VI - probably because it is too memory intensive?

Anyway what is the best method of performing this operation?

To delete elements at the start and end of an array I can index the array through a FOR loop and reduce the number of times it needs to execute, but how do I remove elements from somewhere in the middle of the array?

Chris

July 11, 2018
5:09 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

Deleting from array would be too memory intensive because it would have to reallocate memory each time, and this could potentially fail if no contiguous space is available.  This is not typically done in C for small memory spaces like Arudino.  Since the code is translated to C, it was purposely not included to avoid this from occurring.

What you should do is pre-allocate an array of maximum size using Initialize Array, then when you need to "remove" an element, you would shift all elements below the position up by one using Replace Array.  Inserting can be achieved the same way by shifting then replacing the element.  You can keep track of the actual array size with a separate variable which is decremented or incremented when an element is removed or added.

Forum Timezone: UTC 0
Most Users Ever Online: 100
Currently Online:
3
Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
miche91: 33
scottj: 28
scadao: 23
Member Stats:
Guest Posters: 5
Members: 202
Moderators: 0
Admins: 3
Forum Stats:
Groups: 1
Forums: 2
Topics: 266
Posts: 1222
Newest Members:
pujacontrol
Administrators: geadmin: 22, filipealtoe: 96, Steffan: 356