> I need an offline dynamic memory allocation algorithm. That is, I
> have a number of memory allocation requests each with size (in bytes),
> allocation time and release time that I want to satisfy with one
> contiguous memory segment of a given fixed size. All allocation
> requests are known at program start time.
...
You haven't responded to anyone since you posted. Are you still here?
> All allocation requests are known at program start time.
Does that include the allocation time and release time, or just the
size in bytes? (My assumption is, yes, it includes the times too.)
If you know all information in advance, you can calculate the peak
memory you'll need to allocate, in advance. I.e., every allocation is
only "alive" or active from the allocation time to the release time, so
you just need a chart or array which adds up the bytes for each active
allocation on a per unit of time basis, e.g., second or minute. If the
allocations are randomized or of unknown ordering, compute it again,
repeat over and over.
> AFAIK, this is the offline dynamic memory allocation problem. Since
> the number of requests can be up to 1000 I cannot try all
> combinations.
A computer program can easily brute-force or shotgun test 1000
allocations, and it can do this repeatedly, e.g., billions of times.
This can also be done without actually allocating memory, since you
know the allocations sizes in advance. So, I'm not sure what you're
getting at here as to why you can't try all the combinations, as you can
definitely easily compute all the potential combinations. Even if
you'd rather actually test all the allocations, there has to be a
computer out there somewhere where you can try out all the combinations.
> So my question is: Is there an algorithm that computes an optimal
> allocation in short time, say a few seconds or a minute (probably not
> since NP completeness), and otherwise, is there an algorithm that
> computes a good approximation in that time frame?
It seems that you're asking for something like a perfect hash, but
instead of a perfect hash, you want a perfect memory allocation or
allocator since you know the size and times in advance. I'm not aware
of anything like that.
The fact that you mentioned "NP complete," and seem to be limited for
computing time e.g., shared time on a mainframe, makes me think this may
be a homework assignment for a C.S. course or for a programming
competition. FYI, we don't do homework.
--
Security breaches. Tax haven leaks. Someone is searching for a needle
in a haystack, but the needle isn't there.