UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » Size of array

#1 2009-03-19 03:08 PM

eusta
Member
Registered: 2006-12-13
Posts: 33

Re: Size of array

typedef struct{
    unsigned int *ListofValues;
} SubList;

typedef struct{
    SubList Sublist[NUM_OF_PROCESSORS];
} ListofSubLists;

ListofSubLists Listsofsublists[NUM_OF_PROCESSORS];
SubList SubLists[NUM_OF_PROCESSORS];

Offline

#2 2009-03-19 04:48 PM

jfriesne
Administrator
From: California
Registered: 2005-07-06
Posts: 348
Website

Re: Size of array

typedef struct{
    unsigned int NumValuesInList;
    unsigned int *ListofValues;
} SubList;

Offline

#3 2009-03-19 05:15 PM

eusta
Member
Registered: 2006-12-13
Posts: 33

Re: Size of array

Thanks ! Very logical and simple solution!

Offline

#4 2009-03-27 09:28 PM

eusta
Member
Registered: 2006-12-13
Posts: 33

Re: Size of array

Hello again,

Suppose that i have three sublists SubList1 SubList2 SubList3, how do i merge them in a big Sublist?

Offline

#5 2009-03-28 03:50 AM

jfriesne
Administrator
From: California
Registered: 2005-07-06
Posts: 348
Website

Re: Size of array

Offline

#6 2009-03-28 11:35 AM

eusta
Member
Registered: 2006-12-13
Posts: 33

Re: Size of array

I hoped that there was a more automatic way such as Sublist1+... because the number of the sublists and their sizes are dynamic.

Thanks anyway!

Offline

#7 2009-03-28 12:08 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Size of array

What Jeremy described is an automatic way which can handle dynamic lists.

Use a for loop and for each sublist sum the NumValuesInList, then allocate
enough memory for all of them, and do memcpy in a loop again.

But you can overload the + operator and merge two lists at a time as well
if you want, that's just less efficient (you can't use realloc).

Offline

#8 2009-09-11 11:09 AM

sxf8974#
Guest

Re: Size of array

  • Index
  • » C
  • » Size of array

Board footer

Powered by FluxBB