limit on pointer to array of pointers? 
Author Message
 limit on pointer to array of pointers?

hi all,
         I have a program for testing different search algorithms on a list
of odd integers. but the program always dies when creating a list with more
than 250 elements...

the list is  typedef struct
                    {int count;
                     struct listentry *entry;
                    }list;

listentry is ....{ int key;
                        }listentry;

the list is created by:

   listentry *p;
....snip.....

p=(listentry*)malloc(sizeof(listentry));

if(p)
  ...snip.....

list->entry[i] = *p;
...

this is fine for array lengths up to 250, but for more than this the program
dies at list.entry[i] = *p  (according to if statement, p shouldn't be
NULL).

can anyone say whats going wrong here?

    thanks in advance
    neil



Sat, 27 Oct 2001 03:00:00 GMT  
 limit on pointer to array of pointers?
I think....

Quote:

> hi all,
>          I have a program for testing different search algorithms on a list
> of odd integers. but the program always dies when creating a list with more
> than 250 elements...

> the list is  typedef struct
>                     {int count;
>                      struct listentry *entry;
>                     }list;

> listentry is ....{ int key;
>                         }listentry;

> the list is created by:

>    listentry *p;
> ....snip.....

> p=(listentry*)malloc(sizeof(listentry));

            p=(listentry*)malloc(sizeof(listentry) * 250);

Quote:

> if(p)
>   ...snip.....

> list->entry[i] = *p;

            list->entry = p;

Quote:
> ...

> this is fine for array lengths up to 250, but for more than this the program
> dies at list.entry[i] = *p  (according to if statement, p shouldn't be
> NULL).

> can anyone say whats going wrong here?

>     thanks in advance
>     neil

--
*****************************************
  Miki-Yamaura

*****************************************


Sat, 27 Oct 2001 03:00:00 GMT  
 limit on pointer to array of pointers?


Quote:
> hi all,
>          I have a program for testing different search algorithms on
a list
> of odd integers. but the program always dies when creating a list
with more
> than 250 elements...

> the list is  typedef struct
>                     {int count;
>                      struct listentry *entry;
>                     }list;

> listentry is ....{ int key;
>                         }listentry;

> the list is created by:

>    listentry *p;
> ....snip.....

> p=(listentry*)malloc(sizeof(listentry));

NB it is recommended that you do not cast the return type of malloc,
since this will supress a warning message if the prototype of malloc is
not visible.

Quote:

> if(p)
>   ...snip.....

> list->entry[i] = *p;
> ...

> this is fine for array lengths up to 250, but for more than this the
program
> dies at list.entry[i] = *p  (according to if statement, p shouldn't
be
> NULL).

> can anyone say whats going wrong here?

You do not show us how list and list->entry are allocated. could it be
that you are either not allocating space for list->entry, or allocating
only enough for 250 entries ? You can use realloc to dynamically resize
a malloc'd area.

If this is not the case, please try posting the minimum amount of
working code that demonstrates your problem - you may find the solution
as you do so. If not, then we have more to work with.

--
Tristan Styles #1485

Failure is not an Option
It is Standard Operating Procedure

--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---



Sat, 27 Oct 2001 03:00:00 GMT  
 limit on pointer to array of pointers?
: hi all,
:          I have a program for testing different search algorithms on a list
: of odd integers. but the program always dies when creating a list with more
: than 250 elements...

/* code rearranged for clarity */

: the list is
:
: typedef struct {
:   int count;
:   struct listentry *entry;
: } list;

At a guess this is the type of the head of the list, and you plan
to malloc enough space for the elements later.  The elements have the
form:

: struct listentry {
:   int key;
: } listentry;

But why do you declare a specific entry here, and not just
a tagged structure or typedef?

: the list is created by:

: listentry *p;
: p = (listentry*)malloc(sizeof(listentry));

And this statement gets memory for one element. (btw, drop the cast).

: if(p)
:   list->entry[i] = *p;

Er, list is a type.  And you don't appear to have set aside any
memory either for the head of the list, or for any pointers to
list elements.  There has to be something missing.

: this is fine for array lengths up to 250, but for more than this the program
: dies at list.entry[i] = *p  (according to if statement, p shouldn't be
: NULL).

At a guess, your memory allocation is off.  Try posting a small code
example that shows the problem.  I don't think I've really understood
what you are doing.

Will



Sat, 27 Oct 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Dereferencing f-pointers, arrays of f-pointers, pointers to f-pointers

2. Pointer of Pointers was Pointer of arrays...

3. Pointers: return of pointer to array of pointers to main

4. Array of pointers, pointer to array...

5. array pointer/pointer array

6. arrays pointers array of pointers

7. Pointer to array of pointers

8. pointers to pointers to arrays

9. Pointer to an array of pointers to functions

10. Pointer to Array of Pointers to Strings.

11. pointer to array vs pointer

12. Pointer to pointer of an array

 

 
Powered by phpBB® Forum Software