Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Memblocks cleanup

Author
Message
DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 1st Nov 2019 02:45 Edited at: 1st Nov 2019 10:15
Hi Guys
Playing around with Memblocks

creating Memblocks (first image) selected



Above code works 100%.
First image display and works 100%

The second image loads very very slow... even that the filesize is smaller than the first
Sometimes it don't even load...

Is there a better way to cleanup the memblock array/memory?

Thanks
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 1st Nov 2019 03:18 Edited at: 1st Nov 2019 03:19
is that all the code? AKA, are the variables GLOBALized somewhere else?
(i'm assuming you're loading 1 then 2).

DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 1st Nov 2019 10:14
Hi, not complete code... only a small snippet.
The global and all the others are declared in the program at the top

I assume the problem is when delete the memblock, that's why I only add a piece of snippet to show.
User click 1 or 2 and according to that load the selected sprite into memblock.
But when selecting the second sprite, it just get very slow. Does matter if they select 2 first and then 1, or visa verse

Bored of the Rings
User Banned
Posted: 1st Nov 2019 11:10
hmmm, depending on the size of a memblock, it takes time to delete larger memblocks so there might be a slight delay when deletion occurs.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 1st Nov 2019 17:42 Edited at: 1st Nov 2019 17:47
This is consistent re: time to execute w/ 1080x720 JPGs @ ~240KB:


TotalTime# varies between 0.05 and 0.09 but i expect the HD might be doing other things 1/2 the time.

IE, i can't replicate

DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 2nd Nov 2019 01:50 Edited at: 2nd Nov 2019 01:54
@Virtual Nomad
Thanks.

I put together a complete example AGKStudio project

What can I do to speed things up.

Most code I found somewhere on the forum, and just add things together... but still I miss something to speed things up.

Appreciate the help

EDITED: The idea behind this is to do floodfill, for a painting APP

Attachments

Login to view attachments
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 2nd Nov 2019 02:32
DannyD,

I dunno what your goal is, but when working with pixel processing in interpreted languages (and compiled) instruction redundancy is critically important. Depending upon the image size the snippet from your example bellow is wasting millions if not billions of cycles being interpreted..


ie.



Since this bit of code just skimming a linearly laid out chunk of contiguous memory, the GetPixel (among others) has a disproportionate cost at runtime. So that could be inlined.



That's not going to be express either, but the cost of just skimming the buffer at least 10 instructions per pixel... Which adds up



PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 2nd Nov 2019 04:47
I second Kevin's advice, it's one of the key methods to improve performance for an operation like that. When running through that many checks, avoid going into and out of a function with so many redundant lookups to perform such an operation. It can make a big difference.
DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 2nd Nov 2019 06:46
@Kevin Picone
Following this tutorial to floodfill an image, and detect borders where to stop.
https://forum.thegamecreators.com/thread/213305

Completely new to this, so any advice appreciated

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 2nd Nov 2019 08:51 Edited at: 2nd Nov 2019 08:58
@DannyD I think what they are suggesting it would be better if instead of all those calls and creations of a memblocks
you could refine it by making one memblock of the whole image and then when the floodfill algorithm wants a color
use a bit of math. This would speed up the floodfill algorithm 100fold as it wouldn't need to keep creating memblocks
for every pixel detection

the c interpretation looks like

which is a recursive process and there are faster alternatives
but using the above process getpixel could be calculated from one pre made memblock of the whole image
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 2nd Nov 2019 09:27
@fubarpk

Thanks, I will look into this. appreciate the help
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 2nd Nov 2019 09:55
your welcome im not sure if using one big memblock would cause a problem with the recursion tho
as I haven't tested it
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk

Login to post a reply

Server time is: 2024-04-23 23:20:02
Your offset time is: 2024-04-23 23:20:02