Skip to content

Commit eeb948a

Browse files
authored
Add files via upload
1 parent 6e02fa1 commit eeb948a

3 files changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DynamicArray.dll goes here
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// For this example to work, dynamic.h needs to be in Zorro's include folder,
2+
// and DynamicArray.dll must be in the Zorro main folder.
3+
4+
5+
#include <dynamic.h>
6+
7+
typedef struct
8+
{
9+
bool a;
10+
int b;
11+
char c[32];
12+
double d;
13+
14+
} EXAMPLE;
15+
16+
17+
int main()
18+
{
19+
printf("\n%d",sizeof(char));
20+
printf("\n%d",sizeof(EXAMPLE));
21+
22+
int h = darr_new(sizeof(EXAMPLE));
23+
EXAMPLE e1, e2, e3, e4;
24+
memset(&e1, 0, sizeof(EXAMPLE));
25+
memset(&e2, 0, sizeof(EXAMPLE));
26+
memset(&e3, 0, sizeof(EXAMPLE));
27+
memset(&e4, 0, sizeof(EXAMPLE));
28+
29+
e1.a = true; e1.b = 20; strcpy(e1.c,"banana"); e1.d = 24.5;
30+
e2.a = false; e2.b = -50; strcpy(e2.c,"orange"); e2.d = 51.4;
31+
e3.a = true; e3.b = 30; strcpy(e3.c,"cherry"); e3.d = 68.5;
32+
e4.a = false; e4.b = -10; strcpy(e4.c,"bud light lime"); e4.d = 58.4;
33+
34+
darr_reserve(h,5); // the memory will not reallocate until size exceeds five
35+
darr_push_back(h, &e1);
36+
darr_push_back(h, &e2);
37+
darr_push_back(h, &e3);
38+
darr_push_back(h, &e4);
39+
40+
int size = darr_size(h);
41+
printf("\nsize: %d",size);
42+
// EXAMPLE* pEx = (EXAMPLE*)darr_pointer(h, 0);
43+
int i; EXAMPLE* pEx;
44+
for (i = 0; i < size; i++)
45+
{
46+
pEx = darr_pointer(h,i);
47+
const char* tf;
48+
if (pEx->a) tf = "true";
49+
else tf = "false";
50+
printf("\ni: %d, %s, %d, %s, %.2f\n", i, tf, pEx->b, pEx->c, pEx->d);
51+
}
52+
53+
pEx = (EXAMPLE*)darr_pointer(h, 3);
54+
char* pExc = pEx[0].c;
55+
printf("\n");
56+
int j;
57+
for (j = 0; j < 32; j++)
58+
{
59+
char a[2]; a[1] = 0;
60+
a[0]= pExc[j];
61+
if (a[0] == '\0') a[0]='_';
62+
printf("%s",a);
63+
}
64+
//printf("\r\n");
65+
printf("\ndone!");
66+
return 0;
67+
}

zorro_folder/include/dynamic.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifndef windows_h
2+
#include <windows.h>
3+
#endif
4+
5+
// Creates a new dynamic array. Each element of the array has size of sizeof_type.
6+
// Returns a handle to the array.
7+
int __cdecl darr_new(int sizeof_type);
8+
API(darr_new,DynamicArray)
9+
10+
// Returns the size of the dynamic array, in number of elements,
11+
// or zero if the handle does not exist.
12+
int __cdecl darr_size(int handle);
13+
API(darr_size,DynamicArray)
14+
15+
// Returns the size of each individual element,
16+
// or zero if the handle does not exist.
17+
int __cdecl darr_typesize(int handle);
18+
API(darr_typesize,DynamicArray)
19+
20+
// Pushes the input element to the back of the dynamic array.
21+
// If the current
22+
// Returns the new size of the dynamic array, in number of elements,
23+
// or zero if the handle does not exist.
24+
int __cdecl darr_push_back(int handle, void* pElement);
25+
API(darr_push_back,DynamicArray)
26+
27+
// Returns a (temporary) pointer to element number nElement of the array,
28+
// or NULL if the handle does not exist.
29+
// The pointer should be assumed invalid once the array is resized or reserved.
30+
void* __cdecl darr_pointer(int handle, int nElement);
31+
API(darr_pointer,DynamicArray)
32+
33+
// Resizes the array in terms of number of elements.
34+
// Behavior is similar to that of std::vector.
35+
// Returns true if completed, false if handle not recognized.
36+
bool __cdecl darr_resize(int handle, int nSize);
37+
API(darr_resize,DynamicArray)
38+
39+
// Pre-allocates contiguous memory without changing the size of the dynamic array.
40+
// Behavior is similar to that of std::vector.
41+
// Returns true if completed, false if handle not recognized.
42+
bool __cdecl darr_reserve(int handle, int nSize);
43+
API(darr_reserve,DynamicArray)
44+
45+
// De-allocates the dynamic vector from memory
46+
// After this function, the handle will no longer be recognized.
47+
// Returns true if completed, false if handle not recognized.
48+
bool __cdecl darr_destroy(int handle);
49+
API(darr_destroy,DynamicArray)

0 commit comments

Comments
 (0)