I am tasked to write an assembler in C, which lends itself sufficiently well in certain design-pattern scenarios, and in a parsing phase, after tokenization, I need to “fill-in” certain information that was previously ignored by tokenization.
I’ll skip details, but the way I thought to solve this is by having a sole instance of an object (concretely, a structure) that is equal with another. For example, given:
typedef struct { unsigned int day, month, year; } day; ... day *a = singleton_day(9, 3, 1999), *b = singleton_day(9, 3, 1999);
a
and b
will be pointers to the same memory location, as they were instantiated with identical values.
This technique is going to have a beneficial impact on space and algorithmic performance of my code, but I don’t know how to call the instantiation primitives. I’d like to inspire on an alleged design pattern, but I don’t know if it exists or if I should make one up.