TOP Contributors

  1. MIKROE (2752 codes)
  2. Alcides Ramos (372 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (118 codes)
  5. Bugz Bensce (90 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (139064 times)
  2. FAT32 Library (71594 times)
  3. Network Ethernet Library (56989 times)
  4. USB Device Library (47330 times)
  5. Network WiFi Library (43006 times)
  6. FT800 Library (42297 times)
  7. GSM click (29777 times)
  8. mikroSDK (27874 times)
  9. PID Library (26858 times)
  10. microSD click (26129 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
Library

DynArrays

Rating:

0

Author: VCC

Last Updated: 2024-04-21

Package Version: 1.0.0.0

Category: Other Codes

Downloaded: 43 times

Not followed.

License: MIT license  

Dynamic arrays of Byte, Word, DWord and Pointer. Also 2D arrays of Byte and Word, and 3D array of Byte. Can be compiled on desktop (tested with FreePascal) and MCU (for dsPIC and PIC32).

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "DynArrays" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "DynArrays" changes.

Do you want to report abuse regarding "DynArrays".

  • Information
  • Comments (0)
DOWNLOAD LINK RELATED COMPILER CONTAINS
mikroPascal PRO for PIC32
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc

Library Blog

DynArrays is a library which provides several dynamic array datatypes:
1D array of Byte, Word, DWord and PtrUInt (Pointer)
2D array of Byte and Word
3D array of Byte

Tested on (depending on available memory):
  - Desktop (32-bit FreePascal)
  - PIC32MX270F256B
  - PIC32MZ2048EFM144
  - dsPIC33EP512MU810

Features:
- The library comes as a .pas file, which is included by a .mpas file, so it can be compiled for Desktop compilers (e.g. FreePascal) and MCU (mikroPascal for dsPIC and PIC32).
- Various library features can be switched on/off, using compiler directives.
- There are various functions for array initialization, setting length, freeing, adding items, removing items, concatenation etc. Not all datatypes are made equal. Some have more features than others. For example, the arrays of Word and DWord have functions for creating unique values, stored in arrays themeselves.
- There are conversion functions to and from string, for some of the array types.
- Most functions return a boolean result for successfully allocating or reallocating memory.
- Since memory fragmentation is a risk of not being able to allocate more memory, although available, a simple solution was to redirect GetMem and FreeMem calls to two library functions, which modifies the requested datasize, to be multiple of pointer size. This is enabled by defining RoundAlloc compiler directive at project level. This feature causes the fragmentation to be drastically reduced.
Also, to change the number of available memory blocks, in MemManger, the NR_FREE_BLOCKS can be modified like:
{$IFDEF MMFreeBlocks}
  const NR_FREE_BLOCKS = {$I MMFreeBlocks.inc};
{$ELSE}
  const NR_FREE_BLOCKS = 20;
{$ENDIF}

By providing a new MMFreeBlocks.inc file per project, then every project can have its own NR_FREE_BLOCKS value.


Dependencies: MemManager

Requirements:
- Because the compiler's built-in MemMove function is limited to copying a maxium of 65535 bytes, a new function had to be redefined (MemMove32), which is limited to 2147483647 bytes. When required, it can be enabled, by defining RedefineMemMove compiler directive at project level. A similar function, Min32 is defined, to replace the existing Min function, for the same reason. If user applications do not require allocating more than 65535 bytes per array, then the built-in MemMove function is used instead (when RedefineMemMove compiler directive is not defined).
- In MemManager, the MM_error function header has to be uncommented.

Usage example (1D array of Byte):

var
  Arr: TDynArrayOfByte;
begin
  InitDynArrayToEmpty(Arr);  //required, to initialize internal structure (length to 0, and pointer to nil)

  if not SetDynLength(Arr, 3) then // allocate memory
  begin
    //log out of memory error;
    Exit;
  end;

  Arr.Content^[0] := 30;
  Arr.Content^[1] := 40;
  Arr.Content^[2] := 50;

  if not AddByteToDynArray(60, Arr) then
  begin
    //log out of memory error;
    Exit;
  end;

  FreeDynArray(Arr); //deallocate memory
end;

 


Limitations:
 - Not optimized for efficient memory reallocation.
 - Only the above mentioned datatypes are available.
 - Most functions share the same code, i.e. the code is duplicated for the new datatypes.
 - Most functions require more than double the current array size to be available, when reallocating.
 - CheckInitialized<DynArray> functions are available on Desktop only. They raise exceptions when other functions are attempting to use uninitialized arrays. Since compilers do not automatically insert initialization code (i.e. they do not manage these datatypes), users will have to call InitDynArrayToEmpty-like functions, for every new array.
 - The reported memory usage will not be the same on Desktop and MCU, because on Desktop, more memory is required. This is because the datastructures are a bit different on Desktop (they contain one more field), which are allocated using New, instead of GetMem (to be properly initialized).

 

Known issues:
  - CreateUniqueWord and CreateUniqueDWord functions might return unexpected values when their arrays are full.

Tested with:

https://libstock.mikroe.com/projects/view/5702/expectations

ALSO FROM THIS AUTHOR

PIC32MZ EF Osc Calc

1

This is a calculator for PIC32MZ EF oscillator frequencies.

[Learn More]

File Transfer To PIC

0

This is a simple example of file transfer from a desktop client to a PIC32 server, using mikroMedia for PIC32MX7+ board and mikroMedia+ shield for PIC32MX7.

[Learn More]

Resolver connected to AD2S1200 decoder with CmodA7 board

0

ResolverAD2S1200DecA7 is a hardware + software project, which uses AD2S1200 chip, to interface with a resolver, for motor control applications. To talk to the AD2S1200 chip, the Digilent's CmodA7 board is used.

[Learn More]