previous | start | next

ASM II--collections


Original Objective-C ASM model used no collections concepts. It used "raw" C memory allocation
 (from sfsm/src/bfagent.m):
 

1. Declare instance variables for pointers to arrays of structs

 struct BF_rule *rule;       // array of size numrules
 struct BF_rule *rptrtop;    // top of rule array (rule + p->numrules)
 
2. Allocate a big chunk of memory for the array of structs (p->numrules=integer size)
 
  rule = (Rule) getmem(sizeof(RuleStruct)*p->numrules); //gets  memory for structs
  rptrtop = rule + p->numrules;                               //pointer math finds the "last" pointer
 
3.  Step through it with pointer math.
 Rule rptr;
for (rptr = rule; rptr < rptrtop; rptr++) {
        rptr->forecast = 0.0;
        rptr->oldforecast = global_mean;
        rptr->next = NULL;
        rptr->oldnext = NULL;
}
Note :

previous | start | next