MrDeathNote wrote:avansc wrote:
3. yes i said dynamically allocating memory is VERY SLOW. but it was obviously a hyperbole. I think we call can agree that allocating at map change once is negligible. you will spend more time loading images in.
That really depends on if you have maps of different sizes, if you do then you need to reallocate every time or it kinda destroys the point of making it dynamic in the first place. If you have to reallocate every time you hit a warp that could cause problems, especially on DC and PSP.
Im not sure what you are trying to say, but the allocating time point is irrelevant, loading the actual map data and textures (disk access) is your bottle neck here. they will take MUCH MUCH longer then allocating memory on the heap.
Edit: here are some numbers so you can think about it
allocated [7][256][256] bytes on heap and stack, i was going to do 7.1024.1024 but the stack crapped out.
iterations 100,1000,10000,100000,100000
time for heap in microseconds 55,444,4393,44969,438256
time for stack in microseconds 1,3,28,282,3071
stack is faster by factor of 55x,148x,157x,159x,143x respectively
Now you can see why i said the heap** is VERY SLOW.
okay... now lets actually look at the numbers.
if you so happen to change the map 1000000 timer consecutively, you'll spend less than half a second allocating memory on the heap. yes its ~150 times faster on the stack. BUT, in no situation will you change the map that many times. its just not possible.
not if you were going to change the map ummm 2 or 3 times very fast (you go into a map and realize you dont need to and directly go back)
you will be spending less than a millionth of a second to allocate memory.
Ultimately, if you have a pallet or sprite sheet to load, or anything you have to load off disk, will take MUCH longer.
at 100 iterations to open and only READ ONE LINE of text from a file, it took 1391us, or 1.4 ms (im sure you can speed this up by maintaining open a few file pointers, as well as saving data in binary format ie, serialize objects so you can just read them in one big chunk).