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
G

George Nistor

@George Nistor
About
Posts
37
Topics
12
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • A pointer reference as l-value
    G George Nistor

    yeap: rule, do not allocate memory to copies. Still I don't understand what happens internally. In the bellow code ptOut will be a parameter on the internal Stack? How are handled params which come as refs? Internaly all the params, pointers etc.. have also their own address? Or they are taken like some kind of aliases.

    class CTest
    {
    private:
    char *a;
    public:
    CTest(int n=10)
    {
    a= new char[10];
    a="george";
    }

    	//By Reference
    void GetPtrEx2(char\* &ptOut)
    {
    	ptOut=a;
    }
    

    };

    C / C++ / MFC help question

  • A pointer reference as l-value
    G George Nistor

    so the ideea in case of c++ pointers will be not to use copies as out params? only references. I mean not in all cases. Here the pointer has already memory allocated. So to use the copy is ok; but I cannot allocate memory to a copy - of a pointer. Does anyone know to explain what is exactly a copy of a pointer and how it is handled internaly?

    class CTest
    {
    private:
    char *a;
    public:
    CTest(int n=10)
    {
    a= new char[10];
    a="george";
    }

    //return by value
    char\* GetPtr()
    {
    	return a;
    }
    

    };

    int _tmain(int argc, _TCHAR* argv[])
    {
    CTest obj;

    char *ry= obj.GetPtr();

    cout<<"sir="<

    C / C++ / MFC help question

  • A pointer reference as l-value
    G George Nistor

    yeap, I guess the ideea is not to use copies as out params.

    C / C++ / MFC help question

  • A pointer reference as l-value
    G George Nistor

    Yes, of course. Still, I am interested to know why the code does not work with both cases, or why only in the second case;

    void setLeft(Node* l) { left = l; };

    Also notice if I do, it works:

    Node \*r= 	p->Left();
    r= new Node(); //error : error C2106: '=' : left operand must be l-value
    

    Maybe because in the second case it references directly a l-value by reference and in the second it uses a copy to a pointer?

    C / C++ / MFC help question

  • A pointer reference as l-value
    G George Nistor

    hi Here is my problem: I don't understand why in the following code the second line is error and the third is ok. In the first case where the error is I will get a copy and in the second reference to the pointer. Why the reference is considered l-value?

    // Node class
    class Node {
    private:
    int key;
    Node* left;
    Node* right;

    typedef Node\* Link;
    

    public:
    Node() { key=-1; left=NULL; right=NULL;};
    void setKey(int aKey) { key = aKey; };
    int Key() { return key; };
    Link Left() { return left; };
    Link& Right() { return right; };
    };

    int _tmain(int argc, _TCHAR* argv[])
    {
    Node *p= new Node();
    p->Left()= new Node(); //error : error C2106: '=' : left operand must be l-value

    p->Right()= new Node(); //this one is lvalue
    
    return 0;
    

    }

    C / C++ / MFC help question

  • Paralel QuickSort with 2 threads running at the same spped
    G George Nistor

    OK, Solved. It works really fast even without a selection first. (I can sort 50 millions of ints in 15 seconds)

    C# question graphics algorithms data-structures help

  • Paralel QuickSort with 2 threads running at the same spped
    G George Nistor

    I use as test a vector with 100 000 ints. It is ordered in Descending order. (another problem I have choosed partition element at one end, result in a small partition on a Descending order data set :) ) I have tried an optimized Insertion and it sorts it in 20s. c++ I think I test the worst case scenario which is N2 for both inserion and quicksort. In average cases it works super fast, in less than a second; I got like you with 10 mils of ints around 3 sec.

    int[] V;
    const int sizeV = 10000000;
    Random rnd = new Random();
    for (int i = 0; i < sizeV; ++i)
    V[i] = rnd.Next(0, 9999999);

    C# question graphics algorithms data-structures help

  • Paralel QuickSort with 2 threads running at the same spped
    G George Nistor

    thanks

    C# question graphics algorithms data-structures help

  • Paralel QuickSort with 2 threads running at the same spped
    G George Nistor

    thanks Alan, I have realized after I looked on the Stack(Int32) Constructor. I fixed the problem and now I was able to run it 2 times faster, in 9-10 seconds for the same dataset.

    C# question graphics algorithms data-structures help

  • Paralel QuickSort with 2 threads running at the same spped
    G George Nistor

    Hi, This quick sort couldn't be so bad. Ok, it is not an optimized QuickSort. I think it depends also on the input data you provide. I have used other sorting algorithms with these data set and I get comparative results. But still I don't have any answer here.

    C# question graphics algorithms data-structures help

  • Paralel QuickSort with 2 threads running at the same spped
    G George Nistor

    Hi, I made a small program which sorts a Vector of 100000 ints. I use a quicksort , not the recursive one. With the single thread version I takes about 22s to complete. -now the problem and the question: I have written a second version which 1. first make a partitioning 2. start an independent thread on eatch subpartition = 2Threads So the sorting continues on 2 separate threads with no locks or anythig to block; I got almost the same time when running. Why happens to run in same interval of time. Will Windows7 be very smart to optimize the code to run on multiple cores even if it is a single thread? I have a x6 Cpu. here is the sample code (test code)

    class VectorSafeConcurency
    {
    int[] V;
    const int sizeV = 100000;
    //Stack numbers = new Stack();

        void push2(Stack s, int a, int b)
        {
            s.Push(b);
            s.Push(a);
        }
    
        public VectorSafeConcurency()
        {
            V= new int\[sizeV\];
    
            int value= sizeV;
    
            for (int i = 0; i < sizeV; ++i)
                V\[i\] = value--;
        }
    
        void exchange(ref int x, ref int y)
        {
            int temp= x; 
            x= y;
            y= temp;
        }
    
        int partition(int\[\] A, int l, int r)
        {
            int i = l - 1;
            int j = r;
            int v= A\[r\];
    
            for(;;)
            {
                while(A\[++i\] \= j) break;
                exchange(ref A\[i\], ref A\[j\]);
            }
            exchange(ref A\[i\], ref A\[r\]);
            return i;
        }
    
        struct ThData
        {
            public int\[\] A;
            public int l;
            public int r;
    
            public ThData(int \[\]a, int i, int j)
            {
                A = a; l = i; r = j;
            }
        }
    
    
        void thWorkerParititoner(object data)
        {
            int\[\] A = ((ThData)data).A;
            int l = ((ThData)data).l;
            int r = ((ThData)data).r;
    
            quicksort(A, l, r);
        }
    
    
        void StartQuicksort(int\[\] A, int l, int r)
        {
            if (r <= l) return;
            int i = partition(A, l, r);
    
            Thread t1 = new Thread(thWorkerParititoner);
            t1.Start(new ThData (A, l, i-1));
    
            Thread t2 = new Thread(thWorkerParititoner);
            t2.Start(new ThData(
    
    C# question graphics algorithms data-structures help

  • entity framework connection objects
    G George Nistor

    yes, I talk about SQL connection. What do you mean by using delegates. To create some functions where I open the connection with using ? ans possibly pass some delegates with the functionality I require?

    C# database sysadmin question

  • entity framework connection objects
    G George Nistor

    Hi How should be used these objects, - do I have to create an object every time in an using block (creating connection every time I need a query) or - I can create the object globally and reused for every query I need? Will the server close this connection if it is idle, and I will have an exception when trying to reuse it? Should be this object(context) thread safe?

    C# database sysadmin question

  • create a new process at runtime
    G George Nistor

    You mean like starting the same process again. I have to see if it not alreadz running I will start it in "master" mode, if it is running in "slave" mode. slave mode is the logger. ps. what I wanted was just not to have a separate exe and still start it like a real PROCESS.

    C# question

  • create a new process at runtime
    G George Nistor

    Hi I need to implement a "real time" logger. The idea is to get the last line logged even if the application hangs one instruction after. Because the logger takes the data from GUI I need also not to overload the GUI thread. The data comes fast in the GUI, so I will implement a LoggerQueue. I have been thinking of creating a new process for the logging and send my information with some basic IPC. the question: Is it possible to create a real time process? I mean not by creating a separate project and a separate exe file. Is it possible to lunch some code in a separate process at run-time?

    C# question

  • Circular list as vector, lock needed?
    G George Nistor

    probably I need some kind of lightweight lock, bacause the call to the Handler can come realy fast and mess up with my array index, which is already done in ConcurrentQueue Class. Even if I use a state bit on every element the index could be messed up by another call just before it is used. I have been wondering how it is implemented. Would be possible this class: ConcurrentQueue Class to e implemented using just Interlock class witout any SpinWait or while loops?

    C# question csharp graphics help

  • Circular list as vector, lock needed?
    G George Nistor

    yes this was my intention to have to indexes one for read, one for write, and because it is in a Handlerfunction it should be executed very fast so I will use a vector - as the circular list (or Buffer). I will try this solution first, after the other with the Thread safe collections. thx

    C# question csharp graphics help

  • Circular list as vector, lock needed?
    G George Nistor

    Hi I use System.Io.Ports and the serial interface to receive data in a Terminal like application. From the .Net driver I have a DataReceivedHandler where I receive call with each small part of information sent on the serial. the problem: I have seen sometime some "garbage info", data from previous read. I suspect the call come realy fast and it happens sometime to get old data. intention: I want to change my current implementation in this DataReceivedHandler to write in a circular list. This list I intend to be a vector where I put struct having 2 fiels: - a State bit or boolean flag - and the information When I write I just check the state bit (which is similar to a lock), and if it is still false I write the info and increase the indexWrite. and now the question: Whould be safe this implementation without using lock{ circularList } when I receive very fast calls to the DataReceivedHandler? george

    C# question csharp graphics help

  • Unable to catch Key.Down in a combox with applied style
    G George Nistor

    Hi I use a ComboBox style (the style from msdn example), but I customized it to replace the standard popup with a datagrid. The problem I have is I can't catch Key.Down with the event handler PreviewKeyDown. The comboBox is defined with the style described. It has to do with the template style applied on the comboBox. Somehow the keydown is caught by the combobox, because I see for few ms the ItemBinding path in the textBox, but it is not caught in the code. I have tried also to put in style somthing like with no success.

    any ideas how to solve it? Is it possible to use my comboBox declared in xaml and override OnPreviewKeyDown in the code behind?

    WPF tutorial wpf help question

  • Using C# dependency property in XAML Triggers
    G George Nistor

    I have solved my problem like here: http://msdn.microsoft.com/en-us/library/system.windows.datatrigger.aspx http://msdn.microsoft.com/en-us/library/ms668604.aspx and I can put different colors in my grid based on the normal property from the Item class.

    WPF csharp css database wpf question
  • Login

  • Don't have an account? Register

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