Search Results

Search found 2 results on 1 pages for 'gnm'.

Page 1/1 | 1 

  • C++ String pointers

    - by gnm
    In my previous app I had an object like this: class myType { public: int a; string b; } It had a lot of instances scattered everywhere and passed around to nearly every function. The app was slow. Profiling said that 95% of time is eaten by the string allocator function. I know how to work with the object above, but not how to work with string pointers. class myType { public: int a; string* b; } They told me to use pointers as above. How much faster is it with a string pointer? What is copied when I copy the object? How to the following using the class with the pointer: Access the string value Modify the string value without modifying the one in the object (copy?) General things that change if I use string pointers?

    Read the article

  • I just don't get the C++ Pointer/Reference system.

    - by gnm
    I've never had problems with references as in Python (implicit) or PHP (explicit &). In PHP you write $p = &$myvar; and you have $p as a reference pointing to $myVar. So I know in C++ you can do this: void setToSomething( int& var ) { var = 123; } int myInt; setToSomething( myInt ); Myint is now 123, why? Doesn't & mean "memory address of" x in C++? What do I do then if var is only the adress to myInt and not a pointer? void setToSomething( int* var ) { var* = 123; } int myInt; int* myIntPtr = &myInt; setToSomething( myIntPtr ); Does the above work as expected? I don't understand the difference between * and & in C++ fully. They tell you & is used to get the adress of a variable, but why IN GODS NAME does that help you in functions etc. like in the first example?

    Read the article

1