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.

Dark GDK / Using dbGetPixelsPointer

Author
Message
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 19th Feb 2008 19:03
I found some discussion on this subject but I'm not sure it's solidified in my thinking processes due to some small conflicts.

The documentation says that it returns an int but the prototype shows DWORD. In either case should it not return either an (int *) or (DWORD *)? I can cast it to either of these but I've feel more comfortable if the value were returned in the format it's to be used.

I suspect this is really intended for Dark Basic backwards compatiblity but we're dealing with a language that was designed to use pointers effeciently.

Lilith, Night Butterfly
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 19th Feb 2008 20:05
There's no performance penalty for casting to a pointer.

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 19th Feb 2008 21:53
Thank GoodNess - I'm a Type Casting NUT! (din't think there was - its supposed to compile to "nothing" kinda. Meaning - no CPU Cycles added for type casting.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 19th Feb 2008 21:58
Quote: "There's no performance penalty for casting to a pointer."


True. My concern was more that in all the years that I've used C++ I don't think I've ever seen a function pass what amounts to an integer needing to be cast as a pointer. I'd get nervous that a memory address is being passed to me as a pure numeric value

Lilith, Night Butterfly
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 19th Feb 2008 22:03 Edited at: 19th Feb 2008 22:15
Quote: "Meaning - no CPU Cycles added for type casting."

It depends what you're doing. Typecasting to a pointer doesn't cost anything. Casting between a float and another type requires a conversion, and casting to a larger variable requires a sign-extend/zero-extend (depending on the source variable).

Quote: "I'd get nervous that a memory address is being passed to me as a pure numeric value"

I wouldn't advise this practice either; if you store an address in a 32-bit variable then you won't ever be able to compile it as a 64-bit application.

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 19th Feb 2008 22:23
Quote: "It depends what you're doing. Typecasting to a pointer doesn't cost anything. Casting between a float and another type requires a conversion, and casting to a larger variable requires a sign-extend/zero-extend (depending on the source variable)."


This is an EXCELLENT point I just kinda knew but SHOULD be pointed out. I usually do the casting you mentioned when it makes sense to cause a type conversion - however - my "Type Casting" and Pointer Math and crazy dereferencing I am always casting SAME SIZED types - int - pointer - 32bit.


Quote: "I wouldn't advise this practice either; if you store an address in a 32-bit variable then you won't ever be able to compile it as a 64-bit application"


Another good point! Personally I NEVER heed. I enjoy the POWER you can derive from a CPU by making use of the ENDIAN your developing in - 32 bit? then I'm 32 bit tricks all day long - and I know it won't compile on 64 bit and I don't care. Why? Am I Daft? Well Yes.. but that's not the point! The reson is I have had to convert my own CODE libraries in the past - and at least when its my own code - and I know what and why I do certain things - I found in a day or two I could successfully convert 50,000 lines of code - because of the consistant patterns - careful frequent backups due to tons of global Search-n-Replaces and stuff.

I Think consistancy in development style is as important as everything else - makes life easier when there is a "system" or a recognizable pattern.

Login to post a reply

Server time is: 2024-11-17 06:28:20
Your offset time is: 2024-11-17 06:28:20