Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Cowcatcher posted:

I'm using fread in VC++ 9 to read a binary file, and it keeps returning me a bad pointer

code:
	int size;
	FILE* fr;
	char* buffer;
	...
	if (fopen_s(&fr, "data.bin", "rb") != 0)
		f = fread (&buffer, sizeof(char), size, fr);
f ends up being the correct number of bytes, but buffer is a bad pointer. What am I doing wrong?


Do you allocate memory for your buffer somewhere in that ellipsis

Adbot
ADBOT LOVES YOU

Cowcatcher
Dec 23, 2005

OUR PEOPLE WERE BORN OF THE SKY

Otto Skorzeny posted:

Do you allocate memory for your buffer somewhere in that ellipsis

yes, I used buffer = (char*)malloc(size);

buffer is fine after allocating, I can read/write, but as soon as fread returns I can't touch it anymore or else it crashes

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
What's errno immediately after all this

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
You don't want the & before buffer in fread; it is causing you to overwrite the address of the buffer you allocated (and promptly overflow into the stack) instead of writing into the buffer you allocated.

Cowcatcher
Dec 23, 2005

OUR PEOPLE WERE BORN OF THE SKY
/\/\/\what he said

Otto Skorzeny posted:

What's errno immediately after all this

I just noticed I'm noobishly passing &buffer instead of buffer :downsgun:

Lexical Unit
Sep 16, 2003

Cowcatcher posted:

code:
if (fopen_s(&fr, "data.bin", "rb") != 0)
Doesn't fopen_s() return 0 on success?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Lexical Unit posted:

Doesn't fopen_s() return 0 on success?

Yes.

MSDN posted:

Return Value

Zero if successful; an error code on failure.

mantralord
Apr 28, 2004
I've been reading lately into compiler design and development, and most notably into compiling to bytecode that is later JIT compiled like .NET and Java do.

Basically what I'm wondering is, what's the point of compiling to bytecode? Why not just store the syntax and program flow trees instead? You know, I'm thinking maybe build the trees out of the original source code, run some non platform-specific optimizations, and then store that. Then when the time comes to JIT, just reload the trees and generate machine code while doing some platform-specific optimizations.

It just seems to retarded to have to compile to a stack machine, just to reverse it again to a register machine (and have to perform flow analysis all over again). The only advantage I see is that I guess the bytecode would be faster to interpret than a tree, but then perhaps you can just generate bytecode out of the trees if you must interpret it.

Is there a reason I'm missing as to why it's not done this way?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

mantralord posted:

Basically what I'm wondering is, what's the point of compiling to bytecode?

Bytecode preserves memory locality during execution much better than abstract trees, which tends to be a worthwhile optimization for most interpreters. Furthermore, there is a preexisting large body of work on optimizing instruction-based compilers, which is very tempting to try to apply.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
There are four things to note here.

The first is that Java bytecode was initially designed solely for interpretation (with a conjectured chance of direct hardware execution); they were not thinking about using bytecode as an IR for a native compiler. So in that case, at least, you're right that it's far from optimal for that purpose.

The second is that interpretation (or analogously an initial "splat" native compile) is a very important execution mode for JITted languages. The bulk of the code in most programs is not executed enough to pay for an optimizing compilation. Anything imposing significant overhead on these initial executions would be very bad.

The third is that the AST, even a binary version thereof, would not be a very good IR for a JIT. If you were designing something purely for last-mile platform-specific optimization and code generation, you would almost certainly want some abstract bytecode representation, probably in SSA form, possibly even with embedded live-ranges information.

The fourth is that these JITs are never designed solely for last-mile optimization, because many of their most powerful optimizations are essentially whole-program optimizations that the language doesn't let you make in advance — you can only do them by detecting that, e.g., class X has no subclasses loaded.

mantralord
Apr 28, 2004

ShoulderDaemon posted:

Bytecode preserves memory locality during execution much better than abstract trees, which tends to be a worthwhile optimization for most interpreters. Furthermore, there is a preexisting large body of work on optimizing instruction-based compilers, which is very tempting to try to apply.

Yeah, thats why I figured directly executing an abstract tree would be slower than bytecode. However, I'm more interested in the final JIT compiled code. The biggest problem I see is having to convert a stack machine back to a flow control tree (so you can do machine-specific optimizations), which seems more difficult than the other way around.

Actually I'm just talking out of my rear end here, maybe the bytecode approach would make sense if I actually tried to implement all these things, but it just seems like you're adding an extra unnecessary layer of abstraction between source code and machine code. Also I'm assuming here that bytecode is just another language that needs to have abstract trees created for it and all that jazz to be able to do a quality translation to machine code, instead of just directly translating it to machine code.

I hear alot of C compilers actually generate bytecode internally instead of using the abstract trees directly...is this true?

mantralord
Apr 28, 2004

rjmccall posted:

There are four things to note here.

The first is that Java bytecode was initially designed solely for interpretation (with a conjectured chance of direct hardware execution); they were not thinking about using bytecode as an IR for a native compiler. So in that case, at least, you're right that it's far from optimal for that purpose.

The second is that interpretation (or analogously an initial "splat" native compile) is a very important execution mode for JITted languages. The bulk of the code in most programs is not executed enough to pay for an optimizing compilation. Anything imposing significant overhead on these initial executions would be very bad.

The third is that the AST, even a binary version thereof, would not be a very good IR for a JIT. If you were designing something purely for last-mile platform-specific optimization and code generation, you would almost certainly want some abstract bytecode representation, probably in SSA form, possibly even with embedded live-ranges information.

The fourth is that these JITs are never designed solely for last-mile optimization, because many of their most powerful optimizations are essentially whole-program optimizations that the language doesn't let you make in advance — you can only do them by detecting that, e.g., class X has no subclasses loaded.

Yeah, you know, I basically just started researching this stuff like yesterday, in my mind I thought that you could do most compilation tasks with a flow of control tree of some sort. I guess I better look up this "SSA" stuff, it might provide some extra insight.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

mantralord posted:

Yeah, you know, I basically just started researching this stuff like yesterday, in my mind I thought that you could do most compilation tasks with a flow of control tree of some sort. I guess I better look up this "SSA" stuff, it might provide some extra insight.

Well, it all sortof depends on what kinds of optimizations you want to do — but yeah, it sounds like you've got a lot of reading ahead of you. Don't hesitate to post (maybe in your own thread) if you have more questions as you go.

tef
May 30, 2004

-> some l-system crap ->
Stacks are also pretty easy to compile to as compared to register machines. Bytecode typically doesn't require as much effort to store as it is pretty linear.

blso Bytecode is typically used for the ease of implementation, rather than efficiency.


Aside: If you're looking into SSA I think there is an optimized graph colouring method for register allocation.

aha:
http://digbib.ubka.uni-karlsruhe.de/volltexte/documents/6532

tef fucked around with this message at 23:37 on Jun 17, 2009

mantralord
Apr 28, 2004
Can anyone recommend a good book on compiler design? I'm currently considering this one, based on absolutely nothing, so I better ask before I end up buying a piece of poo poo book. Keep in mind I already know programming quite well, so an advanced book that doesnt babby me around would be fine by me. You know, something like the K&R of compiler design.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
Aho, Sethi, and Ullman's book is generally considered to be a strong introductory and reference text.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

ShoulderDaemon posted:

Aho, Sethi, and Ullman's book is generally considered to be a strong introductory and reference text.
If you want the K&R of compiler design texts, this is the one. It doesn't gently caress around and is pretty intense.

You may want to pair it with a text on language theory such as the Sipser or the Ullman / Hopcroft, as the Dragon book drops you in the deep end with respect to grammars and whatnot.

It'd be fun to start up a reading group for the Dragon text. I really hope I get to TA the compiler class next year :)

Dijkstracula fucked around with this message at 00:17 on Jun 18, 2009

tef
May 30, 2004

-> some l-system crap ->
On the other hand, the appel books on implementing compilers might be a bit more accessible, but not as deep or thorough coverage.

csammis
Aug 26, 2003

Mental Institution

Dijkstracula posted:

If you want the K&R of compiler design texts, this is the one. It doesn't gently caress around and is pretty intense.

tef posted:

On the other hand, the appel books on implementing compilers might be a bit more accessible, but not as deep or thorough coverage.

I bought both of the aforementioned books for my compiler design class in college (the 1st ed. of the Dragon book and Appel's Modern Compiler Implementation in Java). tef and Dijkstracula provided dead-on descriptions. I loved both of them though, and they are currently sitting on my work bookshelf as I slave away tweaking our internal data query language :v:

rugbert
Mar 26, 2003
yea, fuck you
does anyone remember that desktop interface we all made a few years back? It was called tsDesk or something? It was originally made by 69apples or someone..

I was asked to help with a project recently and if I can find out old work it would really help.

defmacro
Sep 27, 2005
cacio e ping pong

rugbert posted:

does anyone remember that desktop interface we all made a few years back? It was called tsDesk or something? It was originally made by 69apples or someone..

I was asked to help with a project recently and if I can find out old work it would really help.

this?

googling "tsdesk" seemed to help

slovach
Oct 6, 2005
Lennie Fuckin' Briscoe
How fast is the FPU in modern CPU's?

I wrote a bitmap scaling routine and it relies on floats. Speed is obviously nice, is there going to be a very worthwhile gain if I rewrite it for fixed point?



edit: while I'm at it... _ftol is without a doubt slow, so I looked around and sure enough there is a conversion instruction.

I figured I'd just do this
code:
int Round(float f){
	int v;

	__asm{
		fld f
		fistp v
	}
	return v;
}
but compiling under release, it seems to return garbage? Is this a bad compiler setting somewhere or am I retarded.

slovach fucked around with this message at 10:56 on Jun 19, 2009

TSDK
Nov 24, 2003

I got a wooden uploading this one

slovach posted:

edit: while I'm at it... _ftol is without a doubt slow, so I looked around and sure enough there is a conversion instruction.
If you're using VC++, just use the /QIfist switch and change the rounding mode at program start-up, as detailed here:
http://software.intel.com/en-us/articles/fast-floating-point-to-integer-conversions/

Cheesemaster200
Feb 11, 2004

Guard of the Citadel
edit

nevermind

Cheesemaster200 fucked around with this message at 22:21 on Jun 19, 2009

slovach
Oct 6, 2005
Lennie Fuckin' Briscoe

TSDK posted:

If you're using VC++, just use the /QIfist switch and change the rounding mode at program start-up, as detailed here:
http://software.intel.com/en-us/articles/fast-floating-point-to-integer-conversions/

This is certainly more elegant, thanks.

rugbert
Mar 26, 2003
yea, fuck you

defmacro posted:

this?

googling "tsdesk" seemed to help

that page had a bunch of old broken links but I think I found a copy.


I was looking for it for some help on a small project Im working on. How can I run programs located on a user's PC from a link in firefox?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

rugbert posted:

I was looking for it for some help on a small project Im working on. How can I run programs located on a user's PC from a link in firefox?

You'd probably need to use Chrome (the Firefox thing, not the Google browser) since that would be a security nightmare otherwise.

HondaCivet
Oct 16, 2005

And then it falls
And then I fall
And then I know


Can someone tell me about using shared memory in Windows using C++? I need to set up a way for multiple programs to read from one device that is sending in a stream of data and shared memory seems to be the best way. I'd especially like to know about how to deal with the fact that programs need to be reading from it while it's being written to constantly. I am a newbie programmer so I am just not sure where to start.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

HondaCivet posted:

Can someone tell me about using shared memory in Windows using C++? I need to set up a way for multiple programs to read from one device that is sending in a stream of data and shared memory seems to be the best way. I'd especially like to know about how to deal with the fact that programs need to be reading from it while it's being written to constantly. I am a newbie programmer so I am just not sure where to start.

In Windows, shared memory is generally implemented as a memory-mapped file. Boost has a slightly more generic version that may be easier to use (it also has the benefit that if you ever need to switch to UNIX, you don't need to touch anything): http://www.boost.org/doc/libs/1_39_0/doc/html/interprocess/sharedmemorybetweenprocesses.html

There are a bunch of utilities in Boost.Interprocess that might make this easier.

(PS just get on AIM or whatever)

Avenging Dentist fucked around with this message at 23:22 on Jun 22, 2009

Boz0r
Sep 7, 2006
The Rocketship in action.
I've been wracking my brain about this, but my calculus skills aren't that sharp right now.

I have a camera position, a camera target, and a gun all in 3D space. I want to link the positions of the camera position and target to the gun so when it's changed rotation the others follow.

I've tried to avoid updating the positions directly when I rotate the gun, but rather use a global Update() method every time a new frame is drawn.

So I have the gun's old rotation, and I have the new rotation. How do I update the positions here? I assume I have to use some nifty rotation matrix but I suck at that poo poo.

I'm writing this in C# with that XNA Game Studio API if that makes a difference.

POKEMAN SAM
Jul 8, 2004

Boz0r posted:

I've been wracking my brain about this, but my calculus skills aren't that sharp right now.

I have a camera position, a camera target, and a gun all in 3D space. I want to link the positions of the camera position and target to the gun so when it's changed rotation the others follow.

I've tried to avoid updating the positions directly when I rotate the gun, but rather use a global Update() method every time a new frame is drawn.

So I have the gun's old rotation, and I have the new rotation. How do I update the positions here? I assume I have to use some nifty rotation matrix but I suck at that poo poo.

I'm writing this in C# with that XNA Game Studio API if that makes a difference.

Not to poo poo on your parade, but if you're having trouble with this trivial problem, what all do you expect to accomplish with your awesome game?

Boz0r
Sep 7, 2006
The Rocketship in action.

Ugg boots posted:

Not to poo poo on your parade, but if you're having trouble with this trivial problem, what all do you expect to accomplish with your awesome game?

Nothing specific. Just a learning experience.

FSMC
Apr 27, 2003
I love to live this lie

Boz0r posted:

I've been wracking my brain about this, but my calculus skills aren't that sharp right now.

I have a camera position, a camera target, and a gun all in 3D space. I want to link the positions of the camera position and target to the gun so when it's changed rotation the others follow.

I've tried to avoid updating the positions directly when I rotate the gun, but rather use a global Update() method every time a new frame is drawn.

So I have the gun's old rotation, and I have the new rotation. How do I update the positions here? I assume I have to use some nifty rotation matrix but I suck at that poo poo.

I'm writing this in C# with that XNA Game Studio API if that makes a difference.

What I do is just draw a simple diagram of what I want, then use basic high school maths to work out manually what the new positions and angles should be. Then I work out the general transitions and how to implement that in the program. In the end I usually just end up with the standard rotation matrices, etc, (maybe left handed instead of right handed), but I generally understand what's going on then. You may need to be careful looking at the ranges of certain trig functions and fix that as well.

I'm not too sure exactly what you are asking. But I would translate everything so that the gun is at the origin. Then calculate the normal(or vector you want the camera to be from the gun) of the gun surface and using that and the distance of the camera and target to the gun, you can work out the point of the camera and target. Then translate the gun back to it's original position. This would basically make the gun look like it's static and not moving, whatever angle it's at.

nbv4
Aug 21, 2002

by Duchess Gummybuns
nm

nbv4 fucked around with this message at 03:07 on Jun 27, 2009

Wicaeed
Feb 8, 2005
Does this forum have a thread for WMI/VB scripters? I'm pretty new to WMI scripting and I'm trying to do stuff that I haven't been able to find out by googling and searching Microsoft TechNet

tripwire
Nov 19, 2004

        ghost flow
Anyone know any quick painless ways of checking for corrupt/incomplete JPGs on windows? It seems theres a jpeginfo utility for unix but I'm not seeing anything simple like that for windows..

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
aptitude tells me jpeginfo only depends on libc6 and libjpeg62 (which was written by 'The Independent JPEG Group' and itself only depends on libc6), is it portable to windows perhaps?

Blotto Skorzany fucked around with this message at 13:29 on Jun 27, 2009

tripwire
Nov 19, 2004

        ghost flow

Otto Skorzeny posted:

aptitude tells me jpeginfo only depends on libc6 and libjpeg62 (which itself only depends on libc6), is it portable to windows perhaps?
I saw that another similar program was ported to Windows called jpegtran (for lossless rotation I guess). One of the results on google was someone saying that it also notifies you of a premature end of stream if you just feed it jpegs.

I tried it out and it pops up a big stupid focus stealing dialog box :ughh: Not exactly going to work nicely in a shell script.


I'm starting to think I'm better of just doing this from linux, it just seems silly that theres currently no easy way to do this on windows.

Scaevolus
Apr 16, 2007

tripwire posted:

I saw that another similar program was ported to Windows called jpegtran (for lossless rotation I guess). One of the results on google was someone saying that it also notifies you of a premature end of stream if you just feed it jpegs.

I tried it out and it pops up a big stupid focus stealing dialog box :ughh: Not exactly going to work nicely in a shell script.


I'm starting to think I'm better of just doing this from linux, it just seems silly that theres currently no easy way to do this on windows.

You could probably do something with the windows imagemagick.

Adbot
ADBOT LOVES YOU

tripwire
Nov 19, 2004

        ghost flow

Scaevolus posted:

You could probably do something with the windows imagemagick.

Ugh. The first result on google is the site admin (of www.imagemagick.org) responding to this question with

"To detect corrupt images you would need to write your own exception handling methods and intercept the messages as they are thrown."

What the gently caress? No thanks

edit:
Hah, I misunderstood (serves me right for skimming that thread instead of reading the whole thing). I can just call identify --verbose for each image, then check for the presence of "Premature end of data segment" in the output.

tripwire fucked around with this message at 13:45 on Jun 27, 2009

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply