What will take less memory?

Started by
15 comments, last by skwee 17 years, 2 months ago
Hello i want to create map. Map of blocks, i think the map size will be something like 500*500 or 1000*1000 (maybe less dont know right now). I wonder what method will use less memory: 1. Create 400-500 separate blocks each block 32*32px 2. Create 200-300 block by grouping similar blocks to one file: like if i have 10 kinds of grass and each block of grass is 32*32px, so ill group them to one file size 320*320px and than draw only the part i need. 3. Create one file with all blocks in it. In method 1 i need to load 400-500 different block, method 2 about 200 blocks, method 3 only one pic but it size will be mapsizeH*32xmapsizeW*32. So what will eat less memory? And if you have other methods tell me. P.S. I think i made a mistake, i needed to post it at Graphics forum i think, admins please move :X

I would love to change the world, but they won’t give me the source code.

Advertisement
couldnt u assign each block type as a number of unique value etc

then in each of your map blocks just use that number to reference which block will be drawn, so for 10 different grass types u would only need 10 block of memory
http://stowelly.co.uk/
Ok i know. I mean if i have 500 textures: grass, stone, wall, sand, water etc..
Of course each block have unique ID form 1 to 500, and if my map going like this:
244 358 358 358 124
Ill draw block number 244 then 358 three times and then 128. The problem that before draw them i need to load them to memory. So what of the methods is better when loading them to memory?

I would love to change the world, but they won’t give me the source code.

forgive me if im wrong theres probably a better method

but just load each texture into memory as you would any other sprite

then just loop through each of your grid lists and render the block that it references

so if you want to draw co-ord 244 358 u just lookup in your class / struct for what graphic it uses then draw that

wont use any more memory as the image is already stored in memory and will do until u destroy it
http://stowelly.co.uk/
Ok ill ask another question:
Lets imagine i have 3 different blocks: a.png, b.png, c.png
a's ID = 1;
b's ID = 2;
c's ID = 3;
It mean at every place in map where i see 1 ill draw a.png, 2 ill draw b.png etc.
Now the question:
When to load them to memory?
When I'm initializing the game? I mean like loading bar at games (before the player even saw the map), and then unload them at end of the game when player quit.
Second way load them "in fly" I mean if now i need to draw a.png ill load him draw him then unload him.

P.S.
Maybe i cant understand you or you cant understand me.
Hmm and when i say "block" i mean a square picture.

I would love to change the world, but they won’t give me the source code.

right at the begining of the game

load a.png, b.png and c.png

you only need these once in memory only one copy of them is necessary

usually you would destroy them at the end of game / level whichever is appropriate


you dont need to load them "on the fly" each image will occupy one space in memory no matter how many times its referenced

all you will do when your rendering is say

draw(ID1,X-cordinate,Y-cordinate);

its easy as, you shouldnt be loading up several copies of the same image just to render it several times

hope thats a little clearer, my communication skills are shite lol
http://stowelly.co.uk/
My communication skills are not better then your's :)

Ok so Ill now to rephrase my first question:
Image i have the same three block a.png b.png c.png each block are 32pixels width and 32pixel height. Now what will take less memory?:
1. If i load this three pictures to separate variable or to arrays.
2. If ill create new picture size 32pixel height and 96pixel height, a new image called all.png that contain all the tree images and load him into memory, and them when i need to draw picture number 2 (b.png right :) Ill draw a part of all.png that contain b.png.

I would love to change the world, but they won’t give me the source code.

ah i get you

im assuming each of the blocks of the overall image will be the same size yeh?

so just load the whole image into memory then just have a structure to define each blocks co-ordinates, then just draw this subsection of the picture in the relevant place

if your using directX i have some code snippets i can drag out for you if that would help?
http://stowelly.co.uk/
So you mean creating one large image instead of a lot of small images will take less memory?
And im using SDL not DirectX, thanks anyway.

I would love to change the world, but they won’t give me the source code.

to be honest itll probably take about the same amount of memory, just one big image will be easier to cleanup i suppose, i think its easier to manage with one big "tilemap", but its all about personal preferance really

EDIT:
one advantage of loading them seperatly will mean you can load and delete them as u like.

but may be harder to manage, i.e updating 500 dif filenames
http://stowelly.co.uk/

This topic is closed to new replies.

Advertisement