How careful do I have to be on memory management?

Forgive me if I don’t phrase this quite right - I’m not a programmer.

I’m defining a class which I expect to use in lots of different programs. Part of the point is to have a quick way of defining particular instances of this class. Now the full range of those particular instances is quite large (of the order of several hundred). In any one program I don’t expect to use more than a dozen, but I want to be able to pick and choose from the whole range.

I have a few options as to how best to do this. The brute force method is simply to define the class and then define all the instances. This makes it easy to use, but means that I’ve defined a whole load of stuff that I’m not going to use. An alternative is to group them into families and define a routine that, when called, defines all the instances in that family. This means an extra hoop to go through in the setup routine, but keeps the number of instances down a little. A third option is to make this even more extreme and define a routine that defines the instances according to a list passed by the user.

Ultimately, I guess I could program some variant of all since they aren’t mutually exclusive (well, I guess the first makes the others redundant but a minor variant of it wouldn’t). So my question is really as to whether I should care about this too much. Is there any significant performance hit from loading a load of objects that don’t get used?

Each particular object isn’t very big, just a list of about 4 values, but as I said there are several hundred of them!

I think you won’t encounter any memory issues with the sizes you’re describing. You can compute the amount of memory you might use in a rudimentary fashion as follows.

Assume one primitive number (integer or floating point type) is 4 bytes in size.

Each object of yours has four values, so 4*4 = 16 bytes.

Say you have 300 of them, that’s 300 * 16 = 4800 bytes, or 4.8 KB.

You can probably safely assume about ~40 MB free memory on an iPad 1 before the OS will start to attempt to release memory from other running apps. (This is of course, entirely dependent on your iPad, it’s just an average case we’ve seen.) iPad 2 will likely have a lot more free at any given time.

I have been consistently surprised at both the speed and capacity of codify/lua/iPad - I had similar concerns working with the font stuff I’ve done (a ton of static data, and significant initialization work to use it), largely unfounded I think. Things I keep expecting to have an impact are still unmeasurably fast. while credit is due to the devs, language, and hardware, my guess is that the biggest factor is that my brain was calibrated on a 1.7 MHz 6502 and 48k of ram, and things are a wee bit faster now. (once we routinely don’t have to cut and paste, I expect my code to balloon in size, and still initialize almost instantly)

1.7 MHz 6502 and 48k of ram

Youngster!

Before I discovered codify, I was considering using CBM64 Basic for coding my applications on the iPad (as there’s an app for that) and I was looking forward to getting out all my old code!