Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » create_bitmap() problem.

This thread is locked; no one can reply to it. rss feed Print
 1   2   3   4 
create_bitmap() problem.
GullRaDriel
Member #3,861
September 2003
avatar

Elias: you're re-creating your bitmap each loop ?

Using line in a loop is , i think, normal.
Using create_bitmap inside a loop is, i think , EVIL (the way you post)

EDIT: i mean in a drawing loop

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Elias
Member #358
May 2000

I can do 2937779 create/destroy_bitmap pairs with a 1x1 bitmap in a second, and can do only 44555 lines from 0/0 to 1000/1000 in a second. So now, which one is speed critical? :)

Of course, both times, the additional check would not change it noticeable at all I think.

So, just want to demonstrate that it's hard to decide what is speed critical. OpenGL has error checking for every single function, so we could have it too after 4.2.0. For 4.2.0, ASSERT is simply the way that was chosen for error handling, and since it works perfectly well, no need to change it.

[Edit:] Temporary bitmaps in the draw loop are needed for example if you want a stretch_trans_blit, or stretched_printf, or things like that.

--
"Either help out or stop whining" - Evert

Peter Wang
Member #23
April 2000

So the conclusion should be that assertions should never be disabled unless absolutely critical for speed. Then create_bitmap(0,0) would always abort regardless of whether you use the release or debug version of Allegro. Great!

GullRaDriel
Member #3,861
September 2003
avatar

:p

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Thomas Harte
Member #33
April 2000
avatar

[

Quote:

Temporary bitmaps in the draw loop are needed for example if you want a stretch_trans_blit, or stretched_printf, or things like that.

Temporary bitmaps aren't necessary, they're used there because it makes implementation easier and/or are the fastest method of doing what is required. It's a circular argument. If bitmap creation were substantially slower then (hopefully) it wouldn't be done in things like stretch_trans_blit and stretched_printf (really - 'stretched'? Is someone actually on a mission to create the least orthogonal API?).

Besides which, anything that relies on malloc relies on OS services, so speed is highly dependent on OS. Perhaps this is (another) reason why us OS X'ers see about 1/4 the frame rate of our PC cousins?

Elias
Member #358
May 2000

I wasn't talking about Allegro functions there, it was just an example why you might need create_bitmap in a draw loop (to support my argument that this can't be a criterion what needs error checking and what not).

--
"Either help out or stop whining" - Evert

A J
Member #3,025
December 2002
avatar

so are we in agreement create_bitmap() is not speed critical ?

asserts and a check is the best option ?

___________________________
The more you talk, the more AJ is right. - ML

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

I wasn't talking about Allegro functions there, it was just an example why you might need create_bitmap in a draw loop (to support my argument that this can't be a criterion what needs error checking and what not).

You'd only create the bitmap when you need to, and recycle it for later. In the loop, you'd check that the bitmap exists, and that it's big enough. If not, you make a big enough bitmap, and leave it around for the next iteration. Yeah, this may cause the first iteration to lag, but it's a one-time deal.. the bitmap will stay around so you can use it as-is on subsequent run-throughs (no additional mallocs necessary). I actually did this when I was working with Allegro to do translucent (normal and additive) software polygons.

Quote:

I can do 2937779 create/destroy_bitmap pairs with a 1x1 bitmap in a second, and can do only 44555 lines from 0/0 to 1000/1000 in a second. So now, which one is speed critical?

line is still speed critical, even if it ends up being slower. The idea is that you can use line multiple times in quick succession per frame render. The faster the better. Creating a bitmap, however, doesn't typcially get used outside of initialization (or in the manner I outlined above) where speed isn't as much of an issue.. that a few extra if checks aren't going to cause speed problems for a program.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Carrus85
Member #2,633
August 2002
avatar

Yeah, I myself was wondering why you wouldn't just create a "working" bitmap outside of the loop, and just recycle it... (and destroy/create it again if the size changes for some reason). :)

Michael Jensen
Member #2,870
October 2002
avatar

While I think Elias's line argument is kind of bogus, I really don't think checking for NULL in drawing functions would lead to much of a slower program, in all of my draw loops, functions that take a bitmap as an argument or call create_bitmap etc I always check for null, not that I expect any of them to fail (except incase of a logic error, or file not found error) If I remove the checks my program speed difference is competley unnoticable, plus it's safer to leave them in.

Quote:

No one with a brain would do that, but there are zero size arrays so who's to say you can't make a zero size bitmap.
please use your brain before making counter arguments.</annoyed>

if a zero sized bitmap is allowed then it's destroyal should also be allowed. And saying "no one with a brain would do that" is a completely worthless argument, that having been said, no one with a brain would have posted what you have! :P

Quote:

Changing this in the way suggested will make code run normally (without errors) in release mode and it will cause a crash in debug mode. This is not acceptable.

No it wouldn't.

Quote:

so this would always work:
destroy_bitmap(create_bitmap(w, h));

not if create bitmap returns null -- or did I miss something? are null checks being added to everything? Actually, adding a null check to destroy bitmap isn't a bad idea, I don't think I've evern seen anyone sanley calling destroy_bitmap(bmp) without first checking if bmp is null, and if create_bitmap is not speed critical, why should destroy_bitmap be? it's usually only called when shutting down!

Quote:

Aren't you checking , when doing A=1/B , if B isn't zero ? i hope you do.

I usually don't perform much division unless I'm using doubles... (it's Ok to divide a double by 0, and actually useful.)

Quote:

After 4.2.0, we could implement something like OpenGL, where every function returns an error code. Or maybe even better, provide a global error callback which is called for errors (in which you can e.g. raise an exception - or in C you could use longjmp to jump to a user exception handler).

User-Defined error handlers would be SWEET!

As far as create bitmap goes, to me it makes more sense to let the lib do the checking because it's one if statement, and the create_bitmap could return faster in rare instances where it can pre-determine that it doesn't even have to call malloc. If the user was required to do this, a code bloat could occur, it makes sense to put the check at the base-level so that there's absolutley no chance of it accidently not getting checked for.

Edit:

Quote:

Besides which, anything that relies on malloc relies on OS services, so speed is highly dependent on OS. Perhaps this is (another) reason why us OS X'ers see about 1/4 the frame rate of our PC cousins?

If it is, it would be neat if allegro could allocate a chunk of memory at the beginning of the program and preformed it's own memory managment/allocation on that chunk to bypass the OS's speed issue...

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

not if create bitmap returns null -- or did I miss something?

AFAIK, destroy_bitmap does nothing with a NULL pointer. I simply returns. IMO, anything that create_* returns, destroy_* should accept without problems.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Evert
Member #794
November 2000
avatar

Quote:

if a zero sized bitmap is allowed then it's destroyal should also be allowed.

Yes. Thing is, they're not allowed.

Quote:

I don't think I've evern seen anyone sanley calling destroy_bitmap(bmp) without first checking if bmp is null

In that case, you've never seen my code. create/destroy behaves like alloc/free: it does nothing with a NULL pointer.

Quote:

If the user was required to do this, a code bloat could occur, it makes sense to put the check at the base-level so that there's absolutley no chance of it accidently not getting checked for.

It is the user's responsibility to pass valid, sane, arguments to a function. The library should, in my opinion, do sanity checks in debug mode but not in release mode. Compare the speed difference between the library in debug mode and release mode. It could be minor on your machine and for your programme, but that doesn't mean it would be for everyone.

Quote:

IMO, anything that create_* returns, destroy_* should accept without problems.

Yes, no argument there.

Thomas Harte
Member #33
April 2000
avatar

Quote:

I really don't think checking for NULL in drawing functions would lead to much of a slower program

It shouldn't make much odds at all, it's presumably the difference between:

LD register, pointer value

And:

LD register, pointer value
BRA.Z .return_code

Especially with branch prediction very effectively preventing any sort of stall in close repeated calls it isn't much of a difference.

Quote:

If it is, it would be neat if allegro could allocate a chunk of memory at the beginning of the program and preformed it's own memory managment/allocation on that chunk to bypass the OS's speed issue...

Firstly, it's wild speculation that this particular thing is a speed issue, I was just making the point that most of the time, the way things are implemented on Allegro is dictated by quick tests or by programmer intuition. Since a lot of the non-DOS/Windows versions seem to be very slow then this possibly needs addressing.

Secondly, Allegro is already a 90% bloat library for most people that being DOS-centric in design eats 100% CPU at runtime, can it really justify taking an unnecessarily gigantic chunk of memory as well?

Quote:

It is the user's responsibility to pass valid, sane, arguments to a function. The library should, in my opinion, do sanity checks in debug mode but not in release mode.

Then you definitely want to look at functions such as get_camera_matrix. Expect the user to be able to pass orthogonal 'up' and 'front' vectors or keep things normalised at their end? Nah, lets just force two sqrts and a bunch of dot products on them.

EDIT: probably the smartest thing to do instead of a function by function disassembly is to work out all the anti-patterns in Allegro? I'm new to this, but I definitely spot abstraction inversion, accidental complexity, busy waiting, code momentum, continuous obsolescence, creeping featurism, procedural code and the aura of a stovepipe system.

But I assume 4.3 will be a clean sweep of much of this, or at least an API that allows a clean sweep?

A J
Member #3,025
December 2002
avatar

Thomas can you give 1 example in allegro, of each of those anti-patterns you mentioned ? or are you just a warm-body ;)

___________________________
The more you talk, the more AJ is right. - ML

Thomas Harte
Member #33
April 2000
avatar

Quote:

Thomas can you give 1 example in allegro, of each of those anti-patterns you mentioned ? or are you just a warm-body

Can do! I'd never actually heard of this stuff before, but discovered it yesterday while searching for the Gang of Four, a historical political grouping here in the UK. Turns out another Gang of Four wrote a book that expounds most of the terms on that page. Point is, I may well be misunderstanding or misapplying any quantity of the group. Anyway...

abstraction inversion
The bundles and sets of code most of us have self written and squirreled away for screen update, automatically switching between memory buffering, page flipping, etc. A potential argument is that this isn't abstraction inversion because the user is merely collecting together the hardware resources that Allegro abstracts, but when you look at the code for things like the OS X port you discover, for example, that Allegro doesn't tap into any hardware for page flipping but emulates it in software.

accidental complexity
Wikipedia quote: "accidental complexity may be caused by misunderstanding of problems, ineffective planning...". I assert that Allegro has had what amounts to ineffective planning due to its "good idea for DOS, now let's port it!" approach. Complexity is introduced by the array of different video techniques, as described above, as well as the way that FONTs are not composed of normal bitmaps except in 16/24bit mode, the distinction between a VOICE and an AUDIOSTREAM, etc

busy waiting
Demonstrated by almost every Allegro application that attempts to be frame rate indepdendent.

code momentum
Created by things like rotate_stretch_pivot_bitmap as compared to the two other functions rotate_pivot_bitmap and stretch_bitmap. Which are all hypothetical because I don't have the Allegro manual to hand, but you get the point. Compare and contrast with OpenGL or DirectDraw, the former of which uses modal parameters and the latter uses, for the limited functions it has, states attached to objects.

continuous obsolescence
Industry trends have brought Windows to the forefront, the Mac back as a significant player for hobbyist developers and invented Linux as a useable gaming platform in the time since Allegro was first implemented. At the minute much more work seems to go into getting every piece of Allegro to work on every platform it is meant to support than in improving the API, etc. See the huge number of OS X problems being reported (admittedly mostly by me) - 8bit desktop mode not working, joystick input unreliable if you want to allow the user to redefine keys, etc

creeping featurism
Possibly the least controversial of my list. Allegro is historically very guilty of this, although it seems to have stopped lately. So I withdraw this one as a going concern and apologise for raising it.

procedural code
Which in this case means "building indivisible, monolithic solutions to problems by not factoring out commonalities" - see examples of "code momentum" above.

stovepipe system
Defined as "a legacy system which cannot be upgraded or refactored and which must be built around until it can be replaced entirely". See the abandonment of Allegro 5.0 and instead the idea of building a new API over the existing one then gradually filtering out the old stuff.

Aside: it would be very interesting to make a virtual middle layer Allegro DLL that simply flagged which functions were used then passed calls on to the real DLL and then to run a whole bunch of Allegro programs through it and find out what proportion of the API is actually in common use. I may try that one day if I ever return to the Windows fold.

Evert
Member #794
November 2000
avatar

This is somewhat sidetracking the original topic, and I don't think we need another discussion on what things need to be changed in Allegro. ;) We're aware of the problems, but we're only a few people working on this in our spare time. Beside which, 4.2 needs to be out of the way first.

Quote:

Complexity is introduced by the array of different video techniques, as described above, as well as the way that FONTs are not composed of normal bitmaps except in 16/24bit mode

Actually, I 8 bit fonts are normal BITMAPs as well. Only monochrome fonts are different, which is not that surprising considering that Allegro doesn't support monochrome bitmaps.

Quote:

At the minute much more work seems to go into getting every piece of Allegro to work on every platform it is meant to support than in improving the API

As I'm sure you're aware, that's because we want to get 4.2 out. API improvements are post 4.2

Quote:

See the huge number of OS X problems being reported (admittedly mostly by me)

Yes, and do keep them coming! Afterall, we want to fix those (although it's rather hard with most of us not having a Mac).

Quote:

Defined as "a legacy system which cannot be upgraded or refactored and which must be built around until it can be replaced entirely". See the abandonment of Allegro 5.0 and instead the idea of building a new API over the existing one then gradually filtering out the old stuff.

Not sure if you followed why this is, but the reason the `rewrite Allegro 5 from scratch' idea was dropped is that there is simply not enough manpower available to do it. No one has the time for a big undertaking like that.

Thomas Harte
Member #33
April 2000
avatar

Quote:

This is somewhat sidetracking the original topic

I disagree, the topic had already begun "the current implementation decisions affecting Allegro vs the ones we'd like to see"!

Anyway, since all of the concerns are already known or to be addressed after 4.2, things are looking up and as you point out, there isn't much utility in discussing them again.

Just one question, the answer to which I'm sure has been made clear 1,000 times but which I never seem to grasp for very long: where can the API specs for 4.3 be found? Or are they the same as 5.0 was, but without a full rewrite underneath?

Evert
Member #794
November 2000
avatar

Quote:

where can the API specs for 4.3 be found? Or are they the same as 5.0 was, but without a full rewrite underneath?

They're the same as for 5.0, the rationale being that a lot of work and thought was put into those and it'd be a waste not to use it, or to just start over and reinvent all that was considered before.
That said, as things are implemented, issues may pop up that make it nescessary to discuss some things again. Some parts of the 5.0 spec may be so incomplete that we need to discuss them anyway.

About the `rewrite underneath', that is actually part of the plan, but it won't be a rewrite from scratch. Peter [Wang] has worked on the event subsystem, which replaces what was previously in place. There are also new keyboard drivers. I've started on the graphics API, but it still lives on top of the old drivers. Eventually, those will have to go.
The internals will be rewritten, just not as one big chunk and it won't be done from scratch.
Right now, what has been done can really only be seen by checking the CVS commit logs, which isn't really ideal. We'll have to move to a detailed TODO/DONE list... after 4.2. :)

Elias
Member #358
May 2000

Quote:

abstraction inversion
accidental complexity

Yes, that's all the reason why there will be a new version.

Quote:

busy waiting

This has two reasons. One is the current polling nature - so the only way around it is to insert rest(1). The other is that many programs simply don't put in rest(1) on purpose, fearing it will cause worse performance. The events system already implemented in new_api_branch solves this.

Quote:

code momentum
Created by things like rotate_stretch_pivot_bitmap as compared to the two other functions rotate_pivot_bitmap and stretch_bitmap. Which are all hypothetical because I don't have the Allegro manual to hand, but you get the point. Compare and contrast with OpenGL or DirectDraw, the former of which uses modal parameters and the latter uses, for the limited functions it has, states attached to objects.

I don't understand.. you mean, the API has too many functions?

Quote:

continuous obsolescence

As Evert pointed out, in the time of feature freeze before the next stable release after several years it really is wise to do nothing except fixing the existing things.

Quote:

creeping featurism

The problem is, many included things make it easier to use. But there haven't been any much new features added in a long time. Is there any new feature in 4.2.0 we didn't have in 4.0.0? I fully would support a move towards making Allegro more modular though.. even if we then have to package up all the modules again as a single package for anyone to be happy with it.

Quote:

procedural code

I don't see this. There's the long standing bitmap/sprite API problem, and some historic things like the 3D functions, to which this may apply - but the core drivers follow a very clean architecture.

Quote:

stovepipe system
Defined as "a legacy system which cannot be upgraded or refactored and which must be built around until it can be replaced entirely". See the

Well, what is happening is, core parts are upgrade in new_api_branch, and the other code is constantly refactored.. so per your definition this doesn't apply to Allegro.

Quote:

Just one question, the answer to which I'm sure has been made clear 1,000 times but which I never seem to grasp for very long: where can the API specs for 4.3 be found? Or are they the same as 5.0 was, but without a full rewrite underneath?

I'd like there to be a list of things which need to be done, and who is working on what.. my attemps can be seen in the wiki: http://awiki.strangesoft.net/bin/view/Main/AllegroDev

There's not much there yet, but I guess that can be contributed to everyone being busy with 4.2.0 :) I will make sure to document what I want to work and am currently working on there once 4.2.0 is out. Or maybe 4.2.0 is just an excuse for my laziness, we'll see..

--
"Either help out or stop whining" - Evert

Michael Jensen
Member #2,870
October 2002
avatar

Quote:

Firstly, it's wild speculation that this particular thing is a speed issue,

I got that part.

Quote:

Secondly, Allegro is already a 90% bloat library for most people that being DOS-centric in design eats 100% CPU at runtime, can it really justify taking an unnecessarily gigantic chunk of memory as well?

Why not? If people ask we could use Pacman as a scapegoat.

Quote:

Yes. Thing is, they're not allowed.

I get that part too, but the person I was responding too didn't; he said something along the lines of "If it lets you do it..." and I said something along the lines of "well if it lets us do it, then it should work"

Quote:

Yes, no argument there.

Umm if destroy_bitmap should destroy anything create_bitmap makes then create_bitmap should return NULL on passing (0,0) but you seem to be disagreeing on that item... not sure... -- And I was unaware of NULL not crashing destroy_bitmap...

A J
Member #3,025
December 2002
avatar

Quote:

it would be very interesting to make a virtual middle layer Allegro DLL ... find out what proportion of the API is actually in common use

.

my allegro C++ wrapper does func call counting, i get a nice chart at teh bottom of the log file that tells me which functions get (ab)used.

Quote:

don't put in rest(1) on purpose, fearing it will cause worse performance. The events system already implemented in new_api_branch solves this

"solves" or forces ?

___________________________
The more you talk, the more AJ is right. - ML

Evert
Member #794
November 2000
avatar

Quote:

it would be very interesting to make a virtual middle layer Allegro DLL ... find out what proportion of the API is actually in common use

I'd just use a profiler. That's (part of) what it's for, afterall.

Elias
Member #358
May 2000

Quote:

"solves" or forces ?

Solves. You can always busy loop and poll for events with an event based API. It just would be stupid.

Quote:

I'd just use a profiler. That's (part of) what it's for, afterall.

Do we provide a profiling version for MSVC? It indeed sounds like AJ simply wrote his own profiler..

--
"Either help out or stop whining" - Evert

Evert
Member #794
November 2000
avatar

Quote:

Do we provide a profiling version for MSVC?

Not sure. I don't think so, but it shouldn't matter for call counts.
If we don't, then how do people do speed comparisons between MinGW and MSVC? Allegro's test programme?

By the way, Elias, is reply-by-email working for you? It stopped working for me a while back, but it might be a problem on my end (didn't have time to look into it yet).

Elias
Member #358
May 2000

2005-08-20 at 22:31 +0000, Evert said:

Quote:
Do we provide a profiling version for MSVC?
Not sure. I don't think so, but it shouldn't matter for call counts.
If we don't, then how do people do speed comparisons between MinGW and
MSVC? Allegro's test programme?

Yes, I've never seen profiler comparisons. It wouldn't be the best thing anyway, since each profiler produces overhead of its own. Some things really take much longer with the profile time, in my experience.

AJ: Do you know if MSVC supports profiling?

And related, I actually have no idea how well the debug version works in MSVC. Can you actually step through Allegro and view variable values and so on, like you can with gdb?

Quote:

By the way, Elias, is reply-by-email working for you? It stopped
working for me a while back, but it might be a problem on my end
(didn't have time to look into it yet).

Not sure, I mostly click the "Go to post" link - unless I mistake it as an [AD] post and then just reply. This is an email reply, in case it arrives.

--
"Either help out or stop whining" - Evert

 1   2   3   4 


Go to: