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
Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I just got a little bummed Boost.Thread only recently got something for setting a thread priority, so I'd have to go update my libraries before I can even mess around with it. Meanwhile I thought I'd ask if it was going to be worthwhile for what I want to do.

I want to have some background work running to update some calculations with whatever spare cycles I have. However, when new data arrives I want to make sure processing reacts and responds to it fairly quickly. Like, within a second, the thread in charge of responding has gotten itself a core and is actively using it the majority of time.

I was originally going to throw together something synchronizing between a background service and this foreground work, when I realized this is probably a job for thread priorities. Generally I'd give the sensitive thread the high priority, and give the background the lower priority. I should be fine if the lower priority stuff still runs a little bit as the higher priority one works.

Something I wonder is how much control I really get. Chances are I'll have to doodle something up just to see for certain, since I haven't actually ever messed with thread priorities before. It's just when I have to update my environment to Boost 1.52 that it gets to be a tough to just throw down an experiment.

This is on Windows, but possibly Linux someday, if that helps.

Adbot
ADBOT LOVES YOU

shrughes
Oct 11, 2008

(call/cc call/cc)
Another question worth considering is, is using the native threading libraries and recognizing Windows with a conditional compilation actually that painful? I'd be willing to use Boost threads as a general concurrency mechanism, but when you're at the point where you're telling the operating system about thread priorities, it sounds like going native might be easier in the long run.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Ehh maybe. I actually swallowed the pill and built Boost 1.52. I have some notions that building Boost had been a pain in the rear end in the past. I think it screwed up finding some paths from Visual Studio in prior versions. This time, it built fine without a problem. Granted, I didn't try to build Boost.Python like I have tried to do previously. I haven't had any time to try any experiments with thread priorities yet though.

That Turkey Story
Mar 30, 2003

Rocko Bonaparte posted:

Ehh maybe. I actually swallowed the pill and built Boost 1.52. I have some notions that building Boost had been a pain in the rear end in the past. I think it screwed up finding some paths from Visual Studio in prior versions.
If you ever have any problems, especially with a common compiler such as Visual C++, post about it to the mailing list. There are lots of people who build with it and Boost won't make it through to a release if VC++ fails for a reason such as that... unless you have a strange setup that's not being tested. Even then, the most you'd likely have to do is manually update your user-config as opposed to relying on the default to try to deduce your settings.

Anyway, use Boost or the new standard threading library unless you have some very specific reason not to. Even if you want to do something that's not directly supported, you can often do so without resorting to always manually dealing with Windows threading for everything. It's generally not an all-or-nothing decision. In other words, using the standard threading library or Boost with a branch or two in the places where you absolutely need to deal with the OS is better than simply doing everything in a non-portable manner.

The Gripper
Sep 14, 2004
i am winner
Is that true for Boost.Python? Last I tried (earlier this year) it was a shitfight and the mailing lists were peppered with "it doesn't work" "works for me!" and no actual real information.

I think I ended up building with MinGW instead of VC++ and even then only one of the examples worked, so I gave up and switched to LUA for what I wanted.

That Turkey Story
Mar 30, 2003

The Gripper posted:

Is that true for Boost.Python? Last I tried (earlier this year) it was a shitfight and the mailing lists were peppered with "it doesn't work" "works for me!" and no actual real information.

I think I ended up building with MinGW instead of VC++ and even then only one of the examples worked, so I gave up and switched to LUA for what I wanted.

Yes. Also, there is a guide specifically for Boost.Python.

The Gripper
Sep 14, 2004
i am winner
That's the guide I followed, and it failed spectacularly over the course of almost 2 days.

I'll give it another try on this system (different VC) and see if it's any better, but honestly the last experience soured me on it enough that I'm not going to expect anything better than total failure!

Edit; Well, it looks like it actually does build properly now. Last time I was lost in an endless sea of unresolved externals. I can't test the embedding feature (tests fail, but that's because Python is built with MSVC++ 2008 and I only have 2010+), but it's good to know it's not thrown into the "doesn't work, don't care" pile.

The Gripper fucked around with this message at 10:15 on Nov 22, 2012

That Turkey Story
Mar 30, 2003

The Gripper posted:

Last time I was lost in an endless sea of unresolved externals.

That's really... odd. Were you building static link libraries or dynamic link libraries?

The Gripper posted:

I can't test the embedding feature (tests fail, but that's because Python is built with MSVC++ 2008 and I only have 2010+), but it's good to know it's not thrown into the "doesn't work, don't care" pile.
There are a lot of people who work on Boost that build with VC++, myself included up until very recently and there are automated builds that use it. If there is some general build failure not related to the compiler's non-compliance, it will be picked up in testing and will block a release (and in most cases, compliance issues will be handled with workarounds as well).

Praseodymi
Aug 26, 2010

I guess this is the place to ask this. I've been given coursework for a C++ class I'm taking but the API he's given us only compiles on older versions of g++, particularly 4.1.2, what we have running in the Linux labs here. I've got g++ running on my Windows 7 home pc through a few different methods, but only the newer versions, and I have no idea how to get it installed. Can someone give me a comprehensive guide to installing g++ 4.1.2?

Vanadium
Jan 8, 2005

Fix the API. :colbert:

OddObserver
Apr 3, 2009

Vanadium posted:

Fix the API. :colbert:

Well, that's one way to learn ;-) Sometimes -fpermissive helps a bit, though it's usually for stuff that's way older than 4.1.2.

Praseodymi
Aug 26, 2010

I'm getting a different error now, so either it's fixed and moved on to something else, or this one is happening before it can even get to the next bit.

code:
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to `WinMain@16'
Any ideas? Googling it doesn't provide any solutions.

nielsm
Jun 1, 2009



Praseodymi posted:

I'm getting a different error now, so either it's fixed and moved on to something else, or this one is happening before it can even get to the next bit.

code:
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to `WinMain@16'
Any ideas? Googling it doesn't provide any solutions.

You're building the program as a Windows subsystem (as opposed to Console subsystem) program, and you don't have the WinMain() entry point function required for that.
There is some flag you need to give, either during compilation or during linking (not sure) to tell that you want a Console subsystem program, i.e. a standard POSIX-style main() entry point.

Bonfire Lit
Jul 9, 2008

If you're one of the sinners who caused this please unfriend me now.

Add -mconsole to your linker flags. Although I believe that is the MinGW default value anyway, so remove any -mwindows or -Wl,-subsystem,windows flags you may use.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

That Turkey Story posted:

That's really... odd. Were you building static link libraries or dynamic link libraries?

There are a lot of people who work on Boost that build with VC++, myself included up until very recently and there are automated builds that use it. If there is some general build failure not related to the compiler's non-compliance, it will be picked up in testing and will block a release (and in most cases, compliance issues will be handled with workarounds as well).
I'm not playing with Boost.Python right now but if it helps I can try to dig up old notes I have on how to make this work. What kicked my rear end in the past was trying to generate a debug build of Python so I could step into the interpreter and deduce what insanity was going on at certain points. One thing that doesn't help there is how Python builds as python_d when in a debug build. I think I wrote some crap down last time I went through it.

On the threading front, I see 1.52 technically doesn't provide a cross-platform way to set a thread priority, but it at least provides a native handle where I could make the appropriate call on whatever platform I'm on. I wrote a little experiment with it overnight, and indeed saw a lower priority thread get less work done in a unit time than a normal priority thread.

Edit: I can't really blame Boost on this because the impression I get of Python culture is it's fine for Python to import native code or other runtime stuff, but it is notoriously a pain in the pass to get it to embed the other way. The global interpreter lock is at the top of my poo poo list there. I hate that drat thing.

Vanadium
Jan 8, 2005

Is there a thing that acts a C preprocessor but instead of spitting out preprocessed source it prints all the defined macros? If not, how else do people autogenerate language bindings that include symbolic constants?

nielsm
Jun 1, 2009



Vanadium posted:

Is there a thing that acts a C preprocessor but instead of spitting out preprocessed source it prints all the defined macros? If not, how else do people autogenerate language bindings that include symbolic constants?

cpp foo.c | grep '#define'
Something like that?



vvv right scratch that

Vanadium
Jan 8, 2005

But cpp processes definitions and does the whole substitution thing, it doesn't output the definitions again. :(

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
-dM with gcc.

OddObserver
Apr 3, 2009

Vanadium posted:

But cpp processes definitions and does the whole substitution thing, it doesn't output the definitions again. :(

gcc has -E -dM which prints defined macros out, see:
http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Preprocessor-Options.html#index-dM-972


(Though I don't see the connection with bindings)

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

OddObserver posted:

(Though I don't see the connection with bindings)

Code that generates bindings want to grab #define constants so that those are bound as well.

Vanadium
Jan 8, 2005

Cheers, I somehow missed that in man gcc, I even only read the preprocessor-specific options. :(

OddObserver posted:

(Though I don't see the connection with bindings)

I wanted to call some termios stuff and it looks like the API is 95% #defined constants. There's a thing that gives me a definition for the termios struct and the dozen functions it comes with, but that doesn't get me very close to fiddling with the right bits.

Vanadium fucked around with this message at 02:50 on Nov 24, 2012

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
If I'm doing division FP math with constants, will MSVC optimize them into multiplications, or will I have to deal with this by hand?

Say something like this:

#define RT_FREQUENCY 44100.0
#define RT_FREQUENCY_RECIP (1.0 / RT_FREQUENCY)

...

double stuff = somevalue * RT_FREQUENCY_RECIP;

Xerophyte
Mar 17, 2008

This space intentionally left blank
Short answer: Most of the time, yep.

Long answer: The two operations aren't strictly equivalent for all values and the compiler takes this into account. As a result /fp:strict and /fp:precise will do that transform if and only if the compiler can guarantee that the result is equivalent. /fp:fast will do algebraic transforms willy-nilly if it thinks it'll gain from them. Here's more detail on the subject. Article is a bit old but I'm pretty sure that part hasn't changed any.

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
Cool, thanks. I'm using fp:fast anyway. The application is a simulation of an analog synthesizer, so precision errors aren't an issue, actually even desired.

jiggerypokery
Feb 1, 2012

...But I could hardly wait six months with a red hot jape like that under me belt.

This is pretty basic so has probably been answered several times in this thread but if it hasn't here goes...

When you have an array of something how do you change the size of the array dynamically without deleting any of the data in it?

can I just do something like

code:
int totalNumberOfObjects = 10;

object* Object

Object = new object[totalNumberOfObjects];

[i] all the object initialisations and stuff[/i]

totalNumberOfObjects++

Object = new object[totalNumberOfObjects];
If so then do I delete unessicary ones as they are no longer needed in a similar fashion?

For some context I am trying to create slices in an audio file. The user clicks to create a point and shift clicks to delete one. They are basically just structures with a couple variables one of which is dependant on data from the previous location in the array.

Cheers!

Edit: Just incase I get the obvious let me google that for you response, the only stuff I have found shows you how to make an array you don't know the size of pre-compile time. What I am trying to do is make an array who's size can change at any point in the running of the program. It's possible I haven't been googling using the right terminology as I am quite new to all this.

jiggerypokery fucked around with this message at 15:42 on Nov 25, 2012

nielsm
Jun 1, 2009



Don't use raw arrays. Use the container types provided by the standard library, such as std::vector.

(The std::vector type will maintain an array for you under the hood. When it needs to grow to fit more items, it allocates a new array of the required size and copies all the objects to the new array, then deletes the old array. Don't do that yourself, implementing it on your own is error-prone and a waste of time when there is already a perfectly good implementation available.)

jiggerypokery
Feb 1, 2012

...But I could hardly wait six months with a red hot jape like that under me belt.

I see. I had the feeling that you would need to do something like this because of pointers just moving through locations in memory. I figured they cant just jump so I must be missing something. :) Nice one!

Edit again: This time google proves fruitful when It comes to making vectors of structures!

jiggerypokery fucked around with this message at 16:07 on Nov 25, 2012

The Gay Bean
Apr 19, 2004
I would just like to write out my understanding of a situation before I make any purchases, and see if people who know what the hell they're doing can find any fault in it.

I am watching lectures for Standford 106B Open Courseware as a way to learn C++ syntax and become a better programmer. The lectures have been really good and informative.

The problem is the homework. The OCW comes with a library that is a binary blob built with VC2005, along with header files. I have tried many things to make this work so that I can do the homework assignments.

1. Download VC 2010 Express, create a blank project, add the header file, add the .lib file to resources, add the lib/include paths to the linker/compiler settings, and compile.

-->Linker errors abound. Am I to conclude that I can't link a static library built with a different version of Visual Studio?

2. Download VC 2005 Express, create a blank project, add the header file, add the .lib file to resources, add the lib/include paths to the linker/compiler settings, and compile.

-->Linker errors. Specifically:

code:
1>------ Build started: Project: template, Configuration: Debug Win32 ------
1>Linking...
1>maze.obj : error LNK2019: unresolved external symbol "double __cdecl GetWindowWidth(void)" (?GetWindowWidth@@YANXZ) referenced in function "private: void __thiscall Maze::configureGraphics(void)" (?configureGraphics@Maze@@AAEXXZ)
1>maze.obj : error LNK2019: unresolved external symbol "double __cdecl GetWindowHeight(void)" (?GetWindowHeight@@YANXZ) referenced in function "private: void __thiscall Maze::configureGraphics(void)" (?configureGraphics@Maze@@AAEXXZ)
1>maze.obj : error LNK2019: unresolved external symbol "void __cdecl UpdateDisplay(void)" (?UpdateDisplay@@YAXXZ) referenced in function "public: void __thiscall Maze::drawMark(struct pointT,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?drawMark@Maze@@QAEXUpointT@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>maze.obj : error LNK2019: unresolved external symbol "void __cdecl DrawLine(double,double)" (?DrawLine@@YAXNN@Z) referenced in function "public: void __thiscall Maze::drawMark(struct pointT,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?drawMark@Maze@@QAEXUpointT@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>maze.obj : error LNK2019: unresolved external symbol "void __cdecl MovePen(double,double)" (?MovePen@@YAXNN@Z) referenced in function "public: void __thiscall Maze::drawMark(struct pointT,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?drawMark@Maze@@QAEXUpointT@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>maze.obj : error LNK2019: unresolved external symbol "void __cdecl SetPenColor(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?SetPenColor@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: void __thiscall Maze::drawMark(struct pointT,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?drawMark@Maze@@QAEXUpointT@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>maze.obj : error LNK2019: unresolved external symbol "void __cdecl Error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Error@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: void __thiscall Maze::drawMark(struct pointT,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?drawMark@Maze@@QAEXUpointT@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>maze.obj : error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl IntegerToString(int)" (?IntegerToString@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) referenced in function "public: void __thiscall Grid<struct Maze::cellT>::resize(int,int)" (?resize@?$Grid@UcellT@Maze@@@@QAEXHH@Z)
1>maze.obj : error LNK2019: unresolved external symbol "void __cdecl InitGraphics(void)" (?InitGraphics@@YAXXZ) referenced in function "public: void __thiscall Maze::draw(void)" (?draw@Maze@@QAEXXZ)
1>C:\Users\John\Desktop\homework 2\template\Debug\template.exe : fatal error LNK1120: 9 unresolved externals
1>Build log was saved at "file://c:\Users\John\Desktop\homework 2\template\template\Debug\BuildLog.htm"
1>template - 10 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
(the function names are all part of the custom Standford libraries)

I honestly have no idea what is wrong with this. It's the same version of the compiler.

3. Google. There exists an open source version of the library that some random learner put together, but it doesn't compile on Windows.

So a couple of general questions.

1. Is it possible to use a binary blob made with a different version of Visual Studio?

2. If I add the path to the library as a library search directory, why would I even have to add it to the project? (I get even more linker errors when I don't add it to the project). Wouldn't it be possible to either add it to the project or have it living in a pointed-to lib directory?

3. As far as I can determine, here is the process for using an external library: point the user-defined include and lib directories to it, add the lib file to your project. Is there some kind of integral step I'm missing?

3. What would you do? Develop for the class in a virtual machine using the hacked-together ones? Install Visual Studio 2005 professional? Find another course? I really like the lecture / homework format of the class--it's familiar and keeps me motivated to have a consistent, well thought-out curriculum--but I've spent more time staring at Windows installer than I have coding.

edit: Worth noting that I am aware that newer versions of the library exist, but the homework assignments for the original class don't compile using them. They have changed the interface a little bit. I managed to do the first homework assignment just porting the skeleton code over, but doing that for every homework assignment seems infeasible.

The Gay Bean fucked around with this message at 08:49 on Nov 26, 2012

Praseodymi
Aug 26, 2010

Praseodymi posted:

I'm getting a different error now, so either it's fixed and moved on to something else, or this one is happening before it can even get to the next bit.

code:
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to `WinMain@16'
Any ideas? Googling it doesn't provide any solutions.

Me again. After giving up briefly and just doing it in the labs I've returned now sure that it's not my fault and that everything should be working, but I'm still getting this error despite my best efforts, and I think that once again this is a problem with the API. I'm passing -mconsole to the linker using -Xlinker, is this correct?

My shiny new error is:
code:
(path stuff)/mingw32/bin/ld.exe: unrecognised emulation mode: console
Supported emulations: i386pe
collect2: ld returned 1 exit status

Praseodymi fucked around with this message at 17:43 on Nov 26, 2012

nielsm
Jun 1, 2009



You should probably post the entire command line that is being executed.

Praseodymi
Aug 26, 2010

Never mind, I got it working. While loving around with the command line I'd got rid of something I shouldn't have :saddowns:!

Vanadium
Jan 8, 2005

I saw http://llvm.org/devmtg/2012-11/Gregor-Modules.pdf, the slides of a presentation by some clang dude about their proposed C module system, but I haven't been able to find much more info on that. Sounds like Gregor is chairing the C++ committee subgroup on modules, and judging from the test/modules/ directory in the clang tree, they seem to be fairly far along already.

So is there some user-facing documentation that I've missed or maybe some more detailed writeup about their proposal? I'd love to play around with some new C++ toys but I haven't been able to prod my clang binary into actually compiling anything :v:

an skeleton
Apr 23, 2012

scowls @ u
I need to make a hash table in c++ to use for a simple two letter word dictionary for school. Does anyone have an idea for a decent/simple hashing function I could use?

nielsm
Jun 1, 2009



an skeleton posted:

I need to make a hash table in c++ to use for a simple two letter word dictionary for school. Does anyone have an idea for a decent/simple hashing function I could use?

First character of word. (Serious.)

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

char1 ^ char2
char1 + char2
etc

b0lt
Apr 29, 2005
*((uint16_t *)(word))

FamDav
Mar 29, 2008
srand(*((uint16_t)(word))), rand();

an skeleton
Apr 23, 2012

scowls @ u
what is uint_16t? Unsigned Int... 16 T? Also, what does unsigned mean?

apologies if these are horrible questions/I deserve to die for asking them.

Adbot
ADBOT LOVES YOU

xgalaxy
Jan 27, 2004
i write code

an skeleton posted:

what is uint_16t? Unsigned Int... 16 T? Also, what does unsigned mean?

apologies if these are horrible questions/I deserve to die for asking them.

uint16_t is platform / compiler independent unsigned 16 bit integer type.
See stdint.h

xgalaxy fucked around with this message at 03:08 on Nov 27, 2012

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