A device for controlling a memory organized to contain a plurality of memory block groups each of which containing a plurality of memory blocks, the device comprising a processor for receiving a request to allocate a free memory block from among the memory blocks of the memory, wherein the processor is configured to: - maintain a first data entity containing first data items so that there is a first data item for each of the memory block groups, each of the first data items indicating how many free memory blocks there are in the memory block group related to this first data item, and - maintain second data entities so that there is a second data entity for each of the memory block groups and each of the second data entities contains second data items so that the number of the second data items in each second data entity is at least the number of the memory blocks in the memory block group related to this second data entity, and, when one or more of the memory blocks of the memory block group related to this second data entity are free, one or more of the second data items of this second data entity contain indicators identifying the free memory blocks from among the memory blocks of the memory block group related to this second data entity, wherein the processor is configured to carry out the following actions in response to receiving the request to allocate a free memory block: - searching, from the first data entity, such a first data item that indicates that there are one or more free memory blocks in the memory block group related to this first data item, - selecting, from among the second data entities, such a second data entity which is related to the memory block group related to the searched first data item, - selecting, from the selected second data entity, such a second data item which carries an indicator of a free memory block, - forming a first address identifying the free memory block to be allocated at least partly on the basis of the searched first data item which indicates the memory block group having at least one free memory block and the indicator of the free memory block, and - updating the searched first data item to correspond to a situation in which the number of free memory blocks in the memory block group related to the searched first data item has decreased by one. - maintain a first data entity containing first data items so that there is a first data item for each of the memory block groups, each of the first data items indicating how many free memory blocks there are in the memory block group related to this first data item, and - maintain second data entities so that there is a second data entity for each of the memory block groups and each of the second data entities contains second data items so that the number of the second data items in each second data entity is at least the number of the memory blocks in the memory block group related to this second data entity, and, when one or more of the memory blocks of the memory block group related to this second data entity are free, one or more of the second data items of this second data entity contain indicators identifying the free memory blocks from among the memory blocks of the memory block group related to this second data entity, - searching, from the first data entity, such a first data item that indicates that there are one or more free memory blocks in the memory block group related to this first data item, - selecting, from among the second data entities, such a second data entity which is related to the memory block group related to the searched first data item, - selecting, from the selected second data entity, such a second data item which carries an indicator of a free memory block, - forming a first address identifying the free memory block to be allocated at least partly on the basis of the searched first data item which indicates the memory block group having at least one free memory block and the indicator of the free memory block, and - updating the searched first data item to correspond to a situation in which the number of free memory blocks in the memory block group related to the searched first data item has decreased by one.