API/C memory mananegemnt problem

Discussion in 'Python' started by Marco Fumana, Mar 10, 2006.

  1. Marco Fumana

    Marco Fumana Guest

    Thank for your help.

    I have try to follow your suggestion but I seem to fail.

    Now my C-module (call it C_Core) code is:

    ***********************************************
    /* create_list function */
    int size=10000000;

    output=(double *) calloc(size, sizeof(double));
    py_output=PyList_New(0);
    for(i=0; i<size; i++){
    tmp=PyFloat_FromDouble(output);
    PyList_Append(py_output, tmp);
    Py_DECREF(tmp); // append adds a reference

    }

    free(outout);

    return py_output;
    **********************************************

    with del statement all memory is relased, but I have a malformed list.

    In python shell:
    # Call C function an create a list
    alfa=C_Core.create_list()

    # check the list
    len(alfa)
    10000000
    # OK
    alfa[1]
    Segmentation fault


    On the other size your last option with
    PyList_SET_ITEM(py_output, tmp) statement
    is quick, but I have still memory problem.

    Any idea?

    Thank a lot
    marco
     
    Marco Fumana, Mar 10, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shlomo Anglister
    Replies:
    1
    Views:
    430
    Default User
    Aug 2, 2004
  2. Praveen, Tayal (IE10)
    Replies:
    0
    Views:
    390
    Praveen, Tayal (IE10)
    Mar 17, 2005
  3. Replies:
    0
    Views:
    310
  4. Tim Peters

    Re: API/C memory mananegemnt problem

    Tim Peters, Mar 11, 2006, in forum: Python
    Replies:
    6
    Views:
    310
    Alex Martelli
    Mar 12, 2006
  5. John123

    Profiling API or Membership API

    John123, Oct 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    394
    John123
    Oct 20, 2006
Loading...

Share This Page