Re: [Vala] Gee LinkedList Problem : Memory allocation fails when list size > 1000000



Example:

NB : The example hereunder works perfectly with a number of elements <=
100,000 but crashes if one when the number of elements to insert in the List
is >= 1000,000 .

Serge.



//-----------

using Gee;
using Posix;


// Struct to hold key, values pairs
struct pair {
    public uint    freq;
    public string   word;
}

// Comparison function for stucts
int comp(pair a, pair b) {
    if( a.freq > b.freq) return -1;
    else if( a.freq < b.freq) return +1;
    else return 0;
}

// Equality function for structs
bool equals (pair a, pair b) {
    if (Posix.strcmp(a.word, b.word) ==0 ) return true;
    else return false;
}

int main(string[] args) {


    //List
    var L = new LinkedList<pair?>( (EqualFunc) equals);

    // Insert in List (to sort)
    pair p = pair();
    for (var i=0; i<1000000; i++) {
        p.word = "test";
        p.freq = 1;
        L.add(p);
    }

    // Sort list
    L.sort( (CompareFunc)comp );


    // Freq distribution
    var i = 0;
    foreach (var item in L) {
        Posix.printf("(%u,\t '%s')\n", item.freq, item.word);
        i++;
        if (i > 10) break;
    }

    return 0;
}

//-----------


On Tue, Jun 14, 2011 at 12:52 AM, Serge Hulne <serge hulne gmail com> wrote:

the result  of the run with gdb is:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00007fff5f3ffff8
0x00000001001500c4 in gee_linked_list_node_free (self=0x103ff67a0) at
linkedlist.c:1182
1182    static void gee_linked_list_node_free (GeeLinkedListNode* self) {
(gdb)

Which seems to point to a memory access problem related to the Gee
GeeLinkedList container.


Apparently the GeeLinkedList tries to free  (a) node(s) which has (have)
not been allocated.


Serge.


On Mon, Jun 13, 2011 at 6:00 PM, Levi Bard <
taktaktaktaktaktaktaktaktaktak gmail com> wrote:

Thanks, I will try that as soon as I can get my hands on  a Linux box,
i.e. by next week-end (installing "nemiver" on a Mac, results in too
many unmet dependencies).

Gdb should work equally well.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]