Requesting memory for your application-Collection of common programming errors

It will depend on a few things – in particular the Operating System, and the language used.

For instance, under MacOS Classic, it was impossible to have more memory allocated after startup – we used to have to go and modify how much memory was allocated using the Finder, and then restart the application. Those were the bad old days.

Modern operating systems will allow for running processes to request more memory – for instance in C, you can use alloc(), malloc(), realloc() or similar to request chunks of memory. In dynamic languages, you just create objects or variables, and more memory is allocated.

In java, there is a limit as to how much memory the JVM has access to – and this can be changed by only restarting the JVM, and passing some arguments to it (sounds like the bad old days, doesn’t it?).

In Objective-C, in addition to the malloc() family of functions, you can also create objects on the heap, using

[object alloc];

which is more often seen as

[[object alloc] init];

Note that this is slightly different to creating objects on the stack – if you are serious about programming learning the difference between these two might be useful, too 🙂

In summary – the programmer needs to ask the OS for more memory. This can be implicit (in dynamic languages, by creating objects, or by creating objects on the heap) or explicitly, such as in C by using alloc()/malloc()/etc.