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
That Turkey Story
Mar 30, 2003

I'm really good at counting.

Adbot
ADBOT LOVES YOU

sarehu
Apr 20, 2007

(call/cc call/cc)

Insurrectum posted:

The way you always do? Explain to me how I have always determined how long it took a program to run.

Oh, I thought you were asking some sort of question specific to Project Euler.

code:
$ time ./foo
foobar foo

real    0m0.026s
user    0m0.002s
sys     0m0.005s

Entheogen
Aug 30, 2004

by Fragmaster

Insurrectum posted:

I'm talking about time differences in the 10 to 100s of milliseconds

http://www.cppreference.com/stddate/index.html

I believe time returns time in mili seconds, or it might be micro. In any case it should be enough for timing your programs.

Insurrectum
Nov 1, 2005

Entheogen posted:

http://www.cppreference.com/stddate/index.html

I believe time returns time in mili seconds, or it might be micro. In any case it should be enough for timing your programs.

I tried that and all I could get was seconds. Here's the solution I found:

code:
int main() {
    int before = GetTickCount();
    ...
    PROGRAM
    ...
    int after = GetTickCount();
    cout << "It took this program " << (after-before) << " milliseconds to run" <<endl;
    cin.get();
    return 0;
}

Entheogen
Aug 30, 2004

by Fragmaster

Insurrectum posted:

I tried that and all I could get was seconds. Here's the solution I found:

code:
int main() {
    int before = GetTickCount();
    ...
    PROGRAM
    ...
    int after = GetTickCount();
    cout << "It took this program " << (after-before) << " milliseconds to run" <<endl;
    cin.get();
    return 0;
}

did you try using clock() method? that should definitely have granularity finer than 1 second.

what does your GetTickCount() do? do you just increment some variable in your loop somewhere in PROGRAM?

slovach
Oct 6, 2005
Lennie Fuckin' Briscoe
Take a look at:
timeBeginPeriod
timeEndPeriod
timeGetTime


and you should be able to get within 1ms.

Insurrectum
Nov 1, 2005

Entheogen posted:

http://www.cppreference.com/stddate/index.html

I believe time returns time in mili seconds, or it might be micro. In any case it should be enough for timing your programs.

That works too.

Avenging Dentist
Oct 1, 2005

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

Entheogen posted:

what does your GetTickCount() do? do you just increment some variable in your loop somewhere in PROGRAM?

GetTickCount is a Windows API function.

If you're on Windows, this article discusses all the Windows timer functions: http://www.mvps.org/directx/articles/selecting_timer_functions.htm

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED
What's an easy way to determine if an arbitrary program will halt? Is there a library for it?

Avenging Dentist
Oct 1, 2005

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

Drx Capio posted:

What's an easy way to determine if an arbitrary program will halt? Is there a library for it?

Check Boost.Turing, it's in the Boost Sandbox.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Drx Capio posted:

What's an easy way to determine if an arbitrary program will halt? Is there a library for it?

I provide a for-pay Turing Oracle service, charged at a reasonable hourly rate. By special arrangement I can set up a web service frontend, although the latency will be quite high for nontrivial programs or when I'm asleep. I cannot guarantee to solve all halting problems, although I will allow you to specify a maximum amount of time you want me to spend working on a problem, and if I can't reach a conclusion I'll give you half off.

Entheogen
Aug 30, 2004

by Fragmaster

Avenging Dentist posted:

Check Boost.Turing, it's in the Boost Sandbox.

hahah, this is a joke, right?

Drx Capio posted:

What's an easy way to determine if an arbitrary program will halt? Is there a library for it?

If you are asking this seriously, then the answer is no. There is no general algorithm that will take another arbitrary algorithm and determine if it will ever halt or not. Look up halting problem on google if you don't believe me.

Entheogen
Aug 30, 2004

by Fragmaster
double post :(

Entheogen fucked around with this message at 21:12 on Jul 13, 2008

sarehu
Apr 20, 2007

(call/cc call/cc)

Entheogen posted:

hahah, this is a joke, right?


If you are asking this seriously, then the answer is no. There is no general algorithm that will take another arbitrary algorithm and determine if it will ever halt or not. Look up halting problem on google if you don't believe me.

That's not true. You can write a program that takes the state of any given computer and tells whether a program on it will halt.

Incoherence
May 22, 2004

POYO AND TEAR

sarehu posted:

That's not true. You can write a program that takes the state of any given computer and tells whether a program on it will halt.
While the amount of state in a computer (not a Turing machine) is technically finite, it'd still take a very long time to either determine that it halts or that it cycles (which is equivalent to it not halting).

ValhallaSmith
Aug 16, 2005
Anyone familiar with LLVM? http://llvm.org/ How does it compare to Phoenix? I've been wanting to do a few experiments with targeting very specific CPUs and it seems like a good fit.

Also, what magic is it that lets MS compilers get a 10-20% edge on GCC/LLVM? Does MS have some crazy superior optimization in the compiler? Or is it because they have a superior library?

ehnus
Apr 16, 2003

Now you're thinking with portals!

ValhallaSmith posted:

Anyone familiar with LLVM? http://llvm.org/ How does it compare to Phoenix? I've been wanting to do a few experiments with targeting very specific CPUs and it seems like a good fit.

Also, what magic is it that lets MS compilers get a 10-20% edge on GCC/LLVM? Does MS have some crazy superior optimization in the compiler? Or is it because they have a superior library?

I work on LLVM daily at work as we use it as a compiler back end, targetting x86 and some PowerPC variations, for languages that we maintain. I don't have any experience with Phoenix so I can't really say how the two compare.

One thing the LLVM project has been quite adamant about is not including optimizations that may be patented and if I recall a few have had to be removed from the project because of this reason. It does get better and better with each successive release, though I haven't done a thorough LLVM vs MSVC comparison yet.

crazypenguin
Mar 9, 2005
nothing witty here, move along

ValhallaSmith posted:

Also, what magic is it that lets MS compilers get a 10-20% edge on GCC/LLVM? Does MS have some crazy superior optimization in the compiler? Or is it because they have a superior library?

The biggest chunk is probably patents (software patents are retarded).

The next biggest chunk for GCC is probably that the software architecture doesn't really lend itself to being changed very easily because god forbid somebody write a nonfree plugin for GCC! Quick! Chop our own arms off!

There's a small amount of it that comes from the fact that Microsoft just has lots of PhDs paid good money just to work on this sort of thing, so it's just better.

Any the last little bit probably comes from the fact that Microsoft mostly just has x86 to worry about, while GCC is more general and supports a ton of different architectures. So they may have the opportunity to push things like vector optimizations up to a higher level than crammed down at the bottom in the instruction selection phase.

Also, I kinda doubt that there's a 20% edge there. Compiler optimization just isn't that good unless it's some pathological special case.

ehnus
Apr 16, 2003

Now you're thinking with portals!

crazypenguin posted:

Any the last little bit probably comes from the fact that Microsoft mostly just has x86 to worry about, while GCC is more general and supports a ton of different architectures. So they may have the opportunity to push things like vector optimizations up to a higher level than crammed down at the bottom in the instruction selection phase.

Microsoft works on several back ends for their compilers, including x86, x86-64, IA-64, PowerPC, ARM, SuperH, and MIPS. I imagine x86 gets a lot of energy directed toward it but such a wide variety of processor support means they can't bias toward it too much.

Mr VacBob
Aug 27, 2003
Was yea ra chs hymmnos mea

crazypenguin posted:

The next biggest chunk for GCC is probably that the software architecture doesn't really lend itself to being changed very easily because god forbid somebody write a nonfree plugin for GCC! Quick! Chop our own arms off!

This isn't true anymore, I wish people would stop acting like it was. There's at least two plugin APIs for GCC and a link-time optimization project coming along now. And the vectorization pass should be about as good or better as MS's; most of the problems come from parts being really old and full of awful spaghetti code written by RMS.

Evil Robot
May 20, 2001
Universally hated.
Grimey Drawer
Stepping a little farther back, the Google style guide seems eminently reasonable. A few of the decisions do not make the purist side of me happy (no exceptions?) but I can understand the practicality behind them.

Although anyone who argues against this style of function definition or loop formatting can go straight to hell, the fuckers:
code:
void foo(void* args)
{
    for (size_t i(0); i < 5; ++i)
    {
        blah blah blah
    }
}

Scaevolus
Apr 16, 2007

Evil Robot posted:

Although anyone who argues against this style of function definition or loop formatting can go straight to hell, the fuckers:
code:
void foo(void* args)
{
    for (size_t i(0); i < 5; ++i)
    {
        blah blah blah
    }
}
I think K&R are better programmers than you. :colbert:

Nubile Cactus
Aug 1, 2004
I am a cactus. :)
Anyone have a list of c++ exercises, from relatively simple to slightly complex? Looking to brush up on c++ and I've always found exercises the best way to do it, but the book I'm using doesn't have any.

Entheogen
Aug 30, 2004

by Fragmaster

Nubile Cactus posted:

Anyone have a list of c++ exercises, from relatively simple to slightly complex? Looking to brush up on c++ and I've always found exercises the best way to do it, but the book I'm using doesn't have any.

You can try doin practice programing competitions problems in C++. It will force you to laern more C++ and STL and also improve algo skills. Probably not that great for OOP learning tho.

I did a bunch of TopCoder problems using C++/STL and I found that it boosted my knowledge of STL quite a bit, since I ended up using it a lot.

JonM1827
Feb 2, 2007
So I have this little script that I made that basically uses the free and ps, and then parses them with with various things. Basically I made it because I have never used awk, and I wanted to try it out.

Here it is in case anybody wanted to take a look at it:

code:
#!/bin/sh

AWK=/usr/bin/awk
EGREP=/bin/egrep
FREE=/usr/bin/free
GREP=/bin/grep
HEAD=/usr/bin/head
PERL=/usr/bin/perl
PS=/bin/ps
SORT=/usr/bin/sort

TOTALMEM=`$FREE -m | $GREP Mem | $PERL -pe 's/Mem:\s+([0-9]+).*/$1/'`
RETVAL=0
case "$1" in
    thin)
          $PS aux | $GREP thin | $EGREP -v 'grep|/bin/sh' |
          $AWK -v totalmem="$TOTALMEM" 'BEGIN { total=0; printf "%-10s %-10s %-10s %s\n", "USER", "%MEM", "PID", "SERVER:PORT"
                                   print "------------------------------------------------" }
                                   { printf "%-10s %-10.2f %-10s %s\n", $1, $4, $2, $13; total+=$4; }
                  END { printf "%-10s %-10.2f %-0.0f MB used\n", "TOTAL:", total, (total/100)*totalmem }'
      RETVAL=$?
  ;;
    php)
        $PS aux | $GREP php5 | $EGREP -v 'grep|/bin/sh' |
        $AWK -v totalmem="$TOTALMEM" 'BEGIN { total=0; printf "%-10s %-10s %-10s %s\n", "USER", "%MEM", "PID", "EXECUTABLE"
                         print "--------------------------------------------------" }
                         { printf "%-10s %-10.2f %-10s %s\n", $1, $4, $2, $11; total+=$4; }
                END { printf "%-10s %-10.2f %-0.0f MB used\n", "TOTAL:", total, (total/100)*totalmem }'
    RETVAL=$?
  ;;
        ten)
        $PS aux | $SORT -nr -k 4 | $HEAD -10 |
        $AWK -v totalmem="$TOTALMEM" 'BEGIN { total=0; printf "%-10s %-10s %-10s %-10s %s\n", "USER", "%MEM", "MEM", "PID", "EXECUTABLE"
                         print "------------------------------------------------------" }
                         { printf "%-10s %-10s %-10.2f %-10s %s\n", $1, $4, ($4/100)*totalmem, $2, $11; total+=$4; }
                END { printf "%-10s %-10.2f %-0.0f MB used\n", "TOTAL:", total, (total/100)*totalmem }'
    RETVAL=$?
        ;;
    *)
      echo "Usage: mem {thin|php|ten}"
      exit 1
  ;;
esac
exit $RETVAL
Now that I have made it I wanted to try and make the same thing except in c++ and with a little bit more functionality. I was looking into libproc, and for the life of me could not figure out how to use it.

I know how to include the files, and make it compile, but I can't find an API or any documentation on how to use it, or if it will even do what I want to do. I tried looking at the source for procpcs (more specifically at the code for free), and I couldn't really follow where everything was going. Also that is written in c not c++.

So basically I was wondering if somebody could point me in the direction of some documentation or for that matter some code that is easier for me to follow.

Sorry if this isn't the right thread for this, but I assume it is as I want to put it into c++... Sorry if the question is stupid, I'm kinda new to c++, especially when it comes to using libraries and such

SuddenExpire
Jun 29, 2005

expired...
I have a syntax question. I have an vector of structs that are referenced by a pointer in this function.

code:
void testFunction(vector<individual_hash> *HashArray)
Now I'm trying to get the size of the passed vector and all I see to get is this error back from Visual Studio. (This is inside the testFunction function)

code:
int testint = HashArray.size();
error: expression must have class type

I have tried the following with no luck of getting a different message.

code:
int testint = &HashArray.size();
int testint = (vector<individual_hash>) &HashArray.size();
Can anybody spot what I'm doing wrong?

sarehu
Apr 20, 2007

(call/cc call/cc)

SuddenExpire posted:

code:
int testint = HashArray.size();
Can anybody spot what I'm doing wrong?

HashArray->size()

SuddenExpire
Jun 29, 2005

expired...

sarehu posted:

HashArray->size()

:doh:

Thanks

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.
Is there a default XML parsing library that is guaranteed to be included on all versions of Windows since 2k SP4? It looks like MSXML 3.0 is only on XP and higher, 4.0 has to be installed separately and 5.0 only comes with Office 2003.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Why not just statically link to TinyXML or something if it's that big a deal?

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.

Avenging Dentist posted:

Why not just statically link to TinyXML or something if it's that big a deal?

Because I'm supposed to remove any non-default dependencies for some unknown loving reason.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Wait what even qualifies as "default"? Also doesn't statically linking remove any (runtime) dependencies? I'm so confused. :psyduck:

FearIt
Mar 11, 2007
Hmm, so I opened up my compiler today, VS2008 Pro and all my code formatting has been changed in a way that totally irks me. Now instead of spaces I have dots, instead of my tabs I have arrows, endlines are shown by squares.

I'm guessing someone messed around with my settings, any goons have any idea how to fix this nonsense?

FearIt
Mar 11, 2007
Nevermind, someone hit control+w. Problem solved.

Paradoxish
Dec 19, 2003

Will you stop going crazy in there?

Plastic Jesus posted:

Because I'm supposed to remove any non-default dependencies for some unknown loving reason.

TinyXML is something like five source/header files. I don't see how linking against it statically will add any dependencies at all since end-users won't have to do anything. It'll be part of your executable. You can even just make the drat thing part of your project.

Entheogen
Aug 30, 2004

by Fragmaster
how exactly does one link statically instead of dynamically in c++?

the only way to link dynamically would be against a DLL or SO file?

when I include .h files in my C++ program and it is linked against a .lib file is that static linking by default?

JonM1827
Feb 2, 2007
So nobody knows anything about libproc? :(

If that's the case does anyone know of an alternative, aside from me parsing through the files manually?

more falafel please
Feb 26, 2005

forums poster

Entheogen posted:

how exactly does one link statically instead of dynamically in c++?

the only way to link dynamically would be against a DLL or SO file?

when I include .h files in my C++ program and it is linked against a .lib file is that static linking by default?

Depends on your build environment. The headers have absolutely nothing to do with how the library is linked.

Look at it this way: each translation unit (for all intents and purposes, a .cpp file after the preprocessor is done with it) you compile defines a set of exported symbols, like main, MyCoolFunction, etc. There's also a set of symbols it references that are not defined in that translation unit: strcpy, SomeLibraryFunction, etc. Each translation unit is compiled into an object file, usually .o or .obj.

The linker's job is to take several object files (and static libraries, which are just collections of object files, .lib or .a generally), resolve the symbols referenced and defined in them, and cram them all together into an executable where all the symbols reference the correct code/data.

When you link against a static library, all the code and data from that library referenced by your program gets copied into the executable. When you link against a dynamic library, the linker generates a little routine that runs before main that loads the dynamic library through the OS and resolves the referenced symbols in that library with the ones in the program.

So I guess in a roundabout way, yes, when you link against a .lib, that's static linking, and all the code you use in that .lib file ends up in your executable.

Lexical Unit
Sep 16, 2003

Paradoxish posted:

TinyXML is something like five source/header files. I don't see how linking against it statically will add any dependencies at all since end-users won't have to do anything. It'll be part of your executable. You can even just make the drat thing part of your project.

For large projects where multiple teams possibly working for different companies need to integrate code bases to provide some solution that's targeted for some specific hardware/software configuration (aka: platform), using code that isn't "default" [sic] (read: isn't speced to be part of the target platform) is a problem.

Sure, you can just compile statically and provide your binaries that will run on the target platform for deployment, but that doesn't solve the issue of integration testing. For my projects it's often the case that multiple companies are coding with respect to some spec, but our projects don't integrate with each other until late in the game. At that point someone from our company has travel to another company to do integration testing. Which just means we compile and run our code in the other company's environment and get both of our systems up and running and see that they actually work together as the spec says they should. Obviously there's usually problems at this point as it's the first time either company has interacted with each others' components.

So the problem with using some library that's not in the spec is that maybe you won't be able to compile your software during integration testing because some other company doesn't have that library installed. And as most often is the case that company would not be willing to install it just for your code, they'd expect you to conform to the spec instead.

One possible solution to that would simply be to package all of the necessary code and libraries into your codebase so you essentially don't care if the other company has them installed or not, because you're taking them along with you. But then there's the issue of wether or not you really want to incorporate some third party's code into your codebase or not. In many situations this would entail a full audit of the third party code and require additional further audits each time the third party released a new version that you might want to incorporate.

TL,DR: Inside I'm really crying about not being able to use boost where I work while I spout out half-assed justifications for it that I've heard from my boss. :smith:

Adbot
ADBOT LOVES YOU

POKEMAN SAM
Jul 8, 2004

Lexical Unit posted:

At that point someone from our company has travel to another company to do integration testing. Which just means we compile and run our code in the other company's environment and get both of our systems up and running and see that they actually work together as the spec says they should. Obviously there's usually problems at this point as it's the first time either company has interacted with each others' components.

How is this a problem from using "non-default" libraries? Instead of including a Header and CPP files in your project you include a Header and LIB files...

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