swarm-support
[Top][All Lists]
Advanced

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

Re: What's wrong with this dynamic matrix allocation


From: Marcus G. Daniels
Subject: Re: What's wrong with this dynamic matrix allocation
Date: 19 Mar 1999 15:31:27 -0800

>>>>> "PJ" == Paul E Johnson <address@hidden> writes:

PJ> Whenever I try to write on one of
PJ> the elements in my matrix, such as minValue[0][0], I get a seg fault and
PJ> the bt points at the command that accesses it.  HEre's my example

Here is an example of how to write a self-contained test-case:
M-x compile, it works.  (Or doesn't, as the case may be.)

#import <simtools.h>
#import <objectbase/SwarmObject.h>
#import <misc.h>

#define NOFSPACES 3
unsigned Dimensionality[] = {3,4,5};

@interface MultiDimSpace: SwarmObject
{
  float **minValue;
  float **maxValue;
}
@end

@implementation MultiDimSpace
- createEnd
{
  unsigned s;
 
  [super createEnd];
  minValue = xmalloc (NOFSPACES * sizeof (float *));
  for (s = 0; s < NOFSPACES; s ++)
    minValue[s] = xmalloc (Dimensionality[s] * sizeof(float));
  
  maxValue = xmalloc (NOFSPACES * sizeof (float *));
  for(s = 0; s < NOFSPACES; s ++)
    maxValue[s] = xmalloc (Dimensionality[s] * sizeof (float));
}

- setMinSpace: (int)space Dim: (int)dim To: (float)value
{
  printf ("writing %u/%u: %f\n", space, dim, value);
  minValue[space][dim] = value;
  return self;
}

- printMinValues
{
  unsigned s, i;

  for (s = 0; s < NOFSPACES; s++)
    for (i = 0; i < Dimensionality[s]; i++)
      printf ("%u %u %f\n", s, i, minValue[s][i]);
  return self;
}

int
main (int argc, const char **argv)
{
  unsigned i, s;
  id world;

  initSwarm (argc, argv);
 
  world = [[MultiDimSpace createBegin: globalZone] createEnd];
  for (s = 0; s < NOFSPACES; s++)
    for(i = 0; i < Dimensionality[s] ; i++)
      [world setMinSpace: s Dim: i To: (i + 1) * (s + 1)];
  [world printMinValues];
}

/*
Local Variables:
compile-command: "/opt/src/mgd/packages/development/egcs/bin/gcc -V 
egcs-2.91.60 -o pj1 pj1.m -g -Wno-import -L/opt/SUNWtcl/8.0/sun4/lib 
-R/opt/SUNWtcl/8.0/sun4/lib -L/opt/SDGblt/2.4g/lib -R/opt/SDGblt/2.4g/lib 
-L/opt/SDGlibffi/1.20/lib -R/opt/SDGlibffi/1.20/lib 
-L/opt/src/mgd/packages/swarm/swarm/lib -R 
/opt/src/mgd/packages/swarm/swarm/lib -L/opt/SDGzlib/1.1.3/lib 
-L/usr/local/X11/lib -R/usr/local/X11/lib -L/usr/openwin/lib -R/usr/openwin/lib 
-L/opt/SDGhdf5/1.0.1/lib -I/opt/src/mgd/packages/swarm/swarm/include -lanalysis 
-lsimtools -lsimtoolsgui -lactivity -ltkobjc -lrandom -lobjectbase  -ldefobj 
-lcollections -lmisc  -ltclobjc -ltk8.0 -ltcl8.0 -lBLT -lsocket -ldl -lnsl 
-L/usr/openwin/lib -lpng -lz -lXpm -lX11 -lffi -lm -lobjc"
End:
*/




                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]