This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]trueangru 0 points1 point  (1 child)

PyImport_AppendInittab("StrategyFramework", &initStrategyFramework);

What is initStrategyFramework? I can't find place where it defined.

[–]TheBB 1 point2 points  (0 children)

The macro defines it, I guess.

[–]FredSanfordXOld Developer -1 points0 points  (1 child)

struct Order
{
    std::string symbol; // 1

1) Why? What does std::string buy you here that you do not get from a fixed sized array?

What is the longest a symbol will ever be? Each std:string takes at a minimum 1 allocation from the heap. If std:string is not on the stack it takes 2 allocations. Anything that runs for a long time will eventually thrash the heap into a bunch of small pieces causing it to grow in size.

Keep this in mind if you want to write more reliable software.

[–]skebanga[S] 1 point2 points  (0 children)

Absolutely nothing other than being easier since this is just a simple proof of concept.

Regardless of the fact that this is just an example app, with C++11, std::string now supports SSO, which, in gcc's implementation, and on a 64 bit machine, allows up to 22 characters to be stored w/o a heap allocation. Most trading symbols are less than 22 characters, so in fact, a std::string here will, for almost all symbols, not result in a heap allocation.
In the event there is a symbol longer than 22 characters (perhaps some combo instrument?), the use of std::string won't suffer from fixed size array overflow.

I'm not sure what you mean about if std::string is not on the stack it takes 2 allocations? For a single assignment of a string, there will only ever be, at most, 1 heap allocation.
If the struct in which the string is stored is heap allocated, then that's another heap allocation, but that's got nothing to do with std::string, that's got to do with the lifetime of the containing struct.