TOP Contributors

  1. MIKROE (2656 codes)
  2. Alcides Ramos (353 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (112 codes)
  5. Chisanga Mumba (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 (136823 times)
  2. FAT32 Library (69986 times)
  3. Network Ethernet Library (55975 times)
  4. USB Device Library (46287 times)
  5. Network WiFi Library (41894 times)
  6. FT800 Library (41203 times)
  7. GSM click (29009 times)
  8. PID Library (26421 times)
  9. mikroSDK (26387 times)
  10. microSD click (25383 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: 4 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.

 

ALSO FROM THIS AUTHOR

DynTFT

10

DynTFT is a set of visual components, inspired by Delphi's VCL. These components are compilable by mikroPascal, Delphi and FreePascal, allowing faster designing and debugging of the UI part of an application. The API features a runtime component registration, to make sure that users won't have to deal with internal handling of mouse/touch events.

[Learn More]

DynTFT Color Themes

0

DynTFT Color Themes are a collection of inc files with color constants, usable by DynTFT components.

[Learn More]

All Tools

5

All Tools is an application, which allows more than 10 user tools to be started from a mikro IDE. It is a menu-based design, as opposed to a list of buttons, thus taking only one button space on the IDE. For each installed tool, two more applications can be executed, one before the tool, and the other, after the tool.

[Learn More]