Skip to content

Commit a4cb38c

Browse files
committed
switching to a regular array for thread_list and setting a MAX_THREADS cap of 256 for better memory management
1 parent 49e48dd commit a4cb38c

File tree

5 files changed

+113
-127
lines changed

5 files changed

+113
-127
lines changed

src/array.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ embArray_create(int type)
7272
case EMB_STITCH:
7373
p->stitch = (EmbStitch*)malloc(CHUNK_SIZE*sizeof(EmbStitch));
7474
break;
75-
case EMB_THREAD:
76-
p->thread = (EmbThread*)malloc(CHUNK_SIZE*sizeof(EmbThread));
77-
break;
7875
case EMB_VECTOR:
7976
p->vector = (EmbVector*)malloc(CHUNK_SIZE*sizeof(EmbVector));
8077
break;
@@ -148,10 +145,6 @@ embArray_resize(EmbArray *p)
148145
p->stitch = (EmbStitch *)realloc(p->stitch, p->length*sizeof(EmbStitch));
149146
if (!p->stitch) return 0;
150147
break;
151-
case EMB_THREAD:
152-
p->thread = (EmbThread *)realloc(p->thread, p->length*sizeof(EmbThread));
153-
if (!p->thread) return 0;
154-
break;
155148
case EMB_VECTOR:
156149
p->vector = (EmbVector *)realloc(p->vector, p->length*sizeof(EmbVector));
157150
if (!p->vector) return 0;
@@ -206,9 +199,6 @@ void embArray_copy(EmbArray *dst, EmbArray *src)
206199
case EMB_STITCH:
207200
memcpy(dst->stitch, src->stitch, sizeof(int)*src->count);
208201
break;
209-
case EMB_THREAD:
210-
memcpy(dst->thread, src->thread, sizeof(int)*src->count);
211-
break;
212202
case EMB_VECTOR:
213203
memcpy(dst->vector, src->vector, sizeof(int)*src->count);
214204
break;
@@ -240,9 +230,9 @@ addGeometry(Polygon, polygon)
240230
addGeometry(Polyline, polyline)
241231
addGeometry(Rect, rect)
242232
addGeometry(Stitch, stitch)
243-
addGeometry(Thread, thread)
244233
addGeometry(Vector, vector)
245234

235+
246236
void embArray_free(EmbArray* p) {
247237
int i;
248238
if (!p) {
@@ -294,9 +284,6 @@ void embArray_free(EmbArray* p) {
294284
case EMB_STITCH:
295285
free(p->stitch);
296286
break;
297-
case EMB_THREAD:
298-
free(p->thread);
299-
break;
300287
case EMB_VECTOR:
301288
free(p->vector);
302289
break;

src/embroidery.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,16 @@ extern "C" {
127127
#define EMB_RECT 9
128128
#define EMB_SPLINE 10
129129
#define EMB_STITCH 11
130-
#define EMB_THREAD 12
131-
#define EMB_VECTOR 13
132-
#define EMB_CHAR 14
133-
#define EMB_ARRAY 15
130+
#define EMB_VECTOR 12
131+
#define EMB_CHAR 13
132+
#define EMB_ARRAY 14
134133

135-
#define EMBFORMAT_UNSUPPORTED 0
136-
#define EMBFORMAT_STITCHONLY 1
137-
#define EMBFORMAT_OBJECTONLY 2
138-
#define EMBFORMAT_STCHANDOBJ 3 /* binary operation: 1+2=3 */
134+
#define MAX_THREADS 256
135+
136+
#define EMBFORMAT_UNSUPPORTED 0
137+
#define EMBFORMAT_STITCHONLY 1
138+
#define EMBFORMAT_OBJECTONLY 2
139+
#define EMBFORMAT_STCHANDOBJ 3 /* binary operation: 1+2=3 */
139140

140141
#define numberOfFormats 61
141142

@@ -714,7 +715,7 @@ struct EmbArray_ {
714715
EmbRect *rect;
715716
EmbSpline *spline;
716717
EmbStitch *stitch;
717-
EmbThread *thread;
718+
EmbThread thread[MAX_THREADS];
718719
EmbVector *vector;
719720
int count;
720721
int length;
@@ -728,8 +729,10 @@ typedef struct EmbPattern_
728729
double hoop_width;
729730
double hoop_height;
730731

732+
EmbThread thread_list[MAX_THREADS];
733+
int n_threads;
734+
731735
EmbArray* stitchList;
732-
EmbArray* threads;
733736
EmbArray* arcs;
734737
EmbArray* circles;
735738
EmbArray* ellipses;

src/fill.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -851,11 +851,11 @@ embPattern_combine(EmbPattern *p1, EmbPattern *p2)
851851
embArray_addStitch(out->stitchList, p2->stitchList->stitch[i]);
852852
}
853853
/* These need to be merged, not appended. */
854-
for (i=0; i<p1->threads->count; i++) {
855-
embArray_addThread(out->threads, p1->threads->thread[i]);
854+
for (i=0; i<p1->n_threads; i++) {
855+
embPattern_addThread(out, p1->thread_list[i]);
856856
}
857-
for (i=0; i<p2->threads->count; i++) {
858-
embArray_addThread(out->threads, p2->threads->thread[i]);
857+
for (i=0; i<p2->n_threads; i++) {
858+
embPattern_addThread(out, p2->thread_list[i]);
859859
}
860860
return out;
861861
}

0 commit comments

Comments
 (0)