Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

Mr Brainley

@Mr Brainley
About
Posts
88
Topics
30
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Accessing ListBox from multiple threads
    M Mr Brainley

    Thanks, i also found help here[^].

    Windows Forms database question

  • Accessing ListBox from multiple threads
    M Mr Brainley

    I have a multithreaded application, and want to access a ListBox from multiple threads. However, if i add an item to the ListBox from a thread different from the one it was created in, the changes are only shown, once i trigger a refresh from the creation thread. Is there any way around that ?

    Windows Forms database question

  • Using a TextBox as Console replacement.
    M Mr Brainley

    Thanks for your help !

    C# question csharp c++ winforms design

  • Using a TextBox as Console replacement.
    M Mr Brainley

    Hello everyone ! I want to write a simple Winforms UI that uses a textbox to output logmessages. This is quite simple, and i have it up and running, but since i am new to C# and Winforms i was wondering what the recommended way/best practice for this problem is. Right now i just write the logmessages into a StringBuilder and update the Text-property of the TextView everytime a new message is added. Deleting older messages is not yet implemented but simple enough. I know that in MFC i could bind the text property to a string and it would be automatically updated both ways. How do i got about that in C#/Winforms ? I know this is a very general question. I do not want a full answer here, just some hints and pointers where to look, since i am at a loss here (i looked up DataBinding on MSDN, but they only talk about DataBases). Thanks, Brainley

    C# question csharp c++ winforms design

  • DateTimePicker MFC - Return ends the program
    M Mr Brainley

    The control was inside a dialogbased MFC-Application, wich is basically a big modal dialog. Pressing Enter triggered the OnOK event, wich by default terminates the application. I can avaid that now.

    C / C++ / MFC c++ help question

  • DateTimePicker MFC - Return ends the program
    M Mr Brainley

    Yes it is.

    C / C++ / MFC c++ help question

  • DateTimePicker MFC - Return ends the program
    M Mr Brainley

    I have tried it to create a dialog with just a DateTime control, same behavior. If i returning false changes nothing.

    C / C++ / MFC c++ help question

  • DateTimePicker MFC - Return ends the program
    M Mr Brainley

    I have a simple problem. I have a DataTimePicker MFC-Control in my Dialog, and whever i press enter while editing it, the application terminates. I have tried to override OnNotify and handle it myself, but that doesn't seem to work. I get the notification, i do something, then i return TRUE (from OnNotify), and then the application terminates. Any suggestions. ? wbr Mr.Brainley

    C / C++ / MFC c++ help question

  • Atomic operations in Win32
    M Mr Brainley

    Here a scenarion. Thread A reads, Thread B writes, the pair consists of V1 and V2 of type int. A reads V1 B writes V1 B writes V2 A reads V2 So now A has a pair that does not belong together. Now consider this : A reads V1 B writes Checksum V1+V2 B writes V1 B writes V2 A reads V2 A checks the Sum -> does not match, so A tries the read again. There are a lot more cases, but they all work out. Using a CRITICAL_SECTION or any other kind of synchronization would mean traps into the OS and context-switches on the wait-operations. In cases where such an optimistic approach is possible, that means the probability of an error, and thus a second or even third read is very low, the performance is higher this way.

    C / C++ / MFC question

  • Atomic operations in Win32
    M Mr Brainley

    I'm writing a procedure where two values, wich always make up a pair, can be changed from one thread, but read from many. I only want to make shure that a read-operation always returns a valid pair (writing is actually limited by a CRITICAL_SECTION). So i use a checksum. The thread reads the variables and then checks the sum against a checksum. If one of the values got changed somewhere in between, the checksum will not match and it will try again. This works, since simple read/write operations on 32-bit Integers are atomic on 32-bit systems. I chose this way because it is much faster that using a lock mechanism, since write operation happen a lot less often (> factor 20) than write-operations.

    C / C++ / MFC question

  • Atomic operations in Win32
    M Mr Brainley

    Ok, sometimes i'm posting over-eagerly. Here is the solution : Interlocked Variable Access[^] In short : the answer is yes. wbr Brainley

    C / C++ / MFC question

  • Atomic operations in Win32
    M Mr Brainley

    Is reading/writing a 32-bit integer on Win32 guaranteed to be atomic ? I could not find that information anywhere. wbr Brainley

    C / C++ / MFC question

  • specialization of STL-map
    M Mr Brainley

    Got it ! I just have to create a custom map that internally keeps a STL-map. Then i can implement all the functions i need and wrap synchronization around them. It's just too simpel.

    ATL / WTL / STL c++ json performance question

  • specialization of STL-map
    M Mr Brainley

    I want to write a specialization of the map-class. I just want to synchronize access to the map in memory, the rest should stay the same. Is there any way to achieve that without completely rewriting the class ? Maybe something like accessing the 'base-class'-method ?

    ATL / WTL / STL c++ json performance question

  • How make a smart reference expose methods of basetype ?
    M Mr Brainley

    1. Yes, it's not used. Thought it might be possible to use it implicitly, so the code looks better. 2. Yes. It actually is a smart pointer internally, but i tried to give it reference semantics and syntax. I need this for a synchronization problem. I have a list of references that is accessed from many threads. If one thread retrieves a reference from that list, and the list is cleared while it works on the reference, the reference remains valid until it goes out of scope (if it is a smart reference). This way i can minimize synchronization to the pure access on the list. Maybe it would be better if i just overloaded the '->'-operator. It would have pointer-syntax then, but that would be ok i guess.

    C / C++ / MFC question help

  • How make a smart reference expose methods of basetype ?
    M Mr Brainley

    MyClassReference ref = MyClass::getInstance();

    ref.doStuff(); // C2039: 'doStuff' is not a member of 'MyClassReference'

    He does not apply the cast implicitly. The following works :

    ((MyClass&)ref).doStuff();

    The compiler told me though, that i have to declare the cast operator

    operator class CNeighbour &();

    in order for this to work. But he still does not apply the cast-operator implicitly.

    C / C++ / MFC question help

  • How make a smart reference expose methods of basetype ?
    M Mr Brainley

    same error : doStuff() is not a member of MyClassReference. -- modified at 6:00 Wednesday 21st February, 2007

    C / C++ / MFC question help

  • How make a smart reference expose methods of basetype ?
    M Mr Brainley

    I have written a reference class for one of my classes. It implements reference counting for that class and that's pretty much it. I have written a cast operator to the class type it references, but the compiler does not use that operator implicitly, so whenever i want to access the referenced object, i have to do an explicit cast (or call a method like getObject()). How can i prevent that ? Here some code to illustrate my problem :

    class MyClassReference;

    class MyClass
    {
    public:
    void doStuff(); // do that thing you do
    static MyClassReference getInstance(); // get an instance of the class, but wrapped in
    // my custom reference-class

    ~MyClass();
    

    private:
    friend class MyClassReference();

    MyClass();                              //  private, so you have to use getInstance();
    
    void addReference();
    void removeRererence();                 //  if (m\_referenceCounter == 0) delete this;
    
    int m\_referenceCounter;
    

    };

    class MyClassReference
    {
    public:
    MyClassReference(MyClass &object); // call addReference
    // fancy copy-constructors and assignment-operators here
    operator MyClass &(); // cast to contained object, not used implicitly

    ~MyClassReference();                //  call removeReference
    

    };

    This is just the principle, feel free to comment on it. wbr Brainley

    C / C++ / MFC question help

  • detect invalid reference
    M Mr Brainley

    Synchronization is of course neccessary (bad seplling ?!), but i want to keep it minimal, since too much synchronization can make a multithreaded application almost sequential, this voiding the advantage of multithreading. It is also correct that the reference should not be stored, but experience tells us, that users always do whatever it takes to crash a program, or the library in that case. So i try to keep my code bulletproof. My approach now is to write a wrapper-class that behaves like a reference, but checks on every access weather the elemennt/vector actually still exists. I'm not sure though if that is the smartest way to do it, it seems like a waste of resources.

    C / C++ / MFC question graphics

  • detect invalid reference
    M Mr Brainley

    That is not the problem. I don't even reference the pointer. I reference an element of the vector that has been destroyed. I could leave the delete on the vector and it would still print nonsense. The reference to the integer stored in the vector has become invalid. I have this problem because i need to implement a wrapper for a map on wich multiple threads can operate concurrently, inserting, reading and deleting. Now one thread could delete an element another thread is currently working on. Since the objects are managed by the map itself i cannot find out when that happened.

    C / C++ / MFC question graphics
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups