Is this bad to do ?

BlitzPlus Forums/BlitzPlus Programming/Is this bad to do ?

skn3(Posted 2003) [#1]
repeat
    myimage=createimage(10,10)
    freeimage(myimage)
until keydown(1)=true


would this have any adverse effects ?


jhocking(Posted 2003) [#2]
Um, what's the point? What are you trying to accomplish?


skn3(Posted 2003) [#3]
I didn't ask that, I asked would it have adverse effects ?

Example
for a=1 to 10
    mybuffer=createimage(a,a)
    freeimage mybuffer
next


Say I had a buffer image ... maybe for a text box. If i was often freeing the iamge, resizing (using createimage) and then redrawing to it, would it cause bad effects with memory ?


Warren(Posted 2003) [#4]
It might cause memory fragmentation after a while, but that would happen with anything where you're allocating/freeing small bits of memory constantly.


skn3(Posted 2003) [#5]
Also if it did not have adverse effects it would be possible to do

Function ResizeImageCanvas(Image,NewWidth,NewHeight)
    NewImage=createiamge(NewWidth,NewHeight)
    copyrect(0,0,imagewidth(Image),imageheight(Image),0,0,imagebuffer(Image),imagebuffer(NewImage))
    freeimage Image
    return NewImage
End function



Beaker(Posted 2003) [#6]
Eventually you might notice the effects of fragmented memory, but it shouldn't cause you big problems. It would be best to avoid it if possible, but if not go for it.


skn3(Posted 2003) [#7]
Ok, that has not given the 100% I was hoping for, I will look for an alternative method :)

thanks


DJWoodgate(Posted 2003) [#8]
I Seem to recall I did something similar to this a while back in some old windows stuff. Don't remember any particularly bad effects. Doing this quite a lot did not seem to adversely effect video memory or fps. Could be there is a better way though I can't think of anything else at the moment.


skn3(Posted 2003) [#9]
I have just gone with not buffering. Will mean there is more video ram for animations and other things later on.


Richard Betson(Posted 2003) [#10]
In my GUI I use ALOT of;

FreeImage img
img=CreateImage(New_Width,New_Height)


I use this for Resizing the Windows which are Image based. I have seen no problems at all. :)


L8r,


FlameDuck(Posted 2003) [#11]
Like people said doing it enough will eventually lead to memory fragmentation. It will be especially noticable on Windows95/98/Me and on computers with only "small" ammounts of memory (small as in less than 256MB). If you've got more than 256 Megs of RAM and a NT (or GNU/Linux/FreeBSD) based operating system, it shouldn't have much impact.

Instead you could perhaps just create the image as big as you'll ever need it and use some of the "ImageRect" commands to only render parts of the graphics. This would be a more "MMU friendly" way of handling resources.


Richard Betson(Posted 2003) [#12]
Thats good to know. But I have not seen any fragmentation. As the system operates now.

L8r,


Oldefoxx(Posted 2003) [#13]
Memory allocation is handled by the operating system. It attempts to allocate new memory from what is currently available but not assigned. If you are requesting and releasing memory in the same amounts, it should not result in any significant change in the allocation strategy. There is an excellent chance you will reclaim much of the same memory that you had requested and released earlier.

But the memory has to be consecutive. If windows does not have a large enough unallocated block, it then attempts to find some way to recluster the assigned memory to create a larger block that will meet your need. It can also attempt to unload one or more processes from physical memory into virtual memory on the hard drive (the Swap memory area) to meet your need. This can result in a significant slowdown of your machine.

Several products attempt to optimize memory usage of your system my attempting to free memory that is tied to processes that are no longer running, or to condense memory into tighter structures so that there are more large blocks available to the memory allocation process when it needs them. If these work as intended, you may find that your machine performs better overall. You may also find that there is less liklihood that the cycles described above will seriously effect performance of your system. Some of these utilities have names like TurboMem, Memory Zipper, and so forth. I personally use Memory Zipper, having done speed trials of several products, and found that it keeps more memory open and my machine tends to run faster. But I have not tried every program of this nature out there.


Tricky(Posted 2003) [#14]
Maybe a direct access command aside from pre-loading is a good idea...

Maybe nice to implent in Blitz...

So let's say...

Global B = LoadImage("Image.bmp")  ; Preloading

DiskImage "Image.bmp",10,10        ; Put directly on the screen without preloading at location (10,10)


Idea?