Revision 752 branches/threaded2/src/linad99/newdar.cpp

newdar.cpp (revision 752)
94 94
    ad_exit(1);
95 95
  }
96 96

  
97
  char * temp_ptr;
97
  char* temp_ptr = nullptr;
98 98

  
99
  unsigned int bytes_needed= sizeof(double_and_int) * sz;
100

  
99 101
  // this routine allocated a block of memory of sizeof(double)*sz bytes
100 102
  // for the gradients of an array or matrix of prevariables 
101

  
102 103
  arr_link * tmp = gradient_structure::ARR_LIST1->free_last;
103

  
104
  unsigned int bytes_needed=sizeof(double_and_int)*sz;
105
  int ss=0;
106
  if (ss)
107
  {
108
    double_and_int * tt=0;
109
    return tt;
110
  }
111

  
112 104
  while (tmp)
113 105
  {
114 106
    if (tmp->size >= bytes_needed)
115 107
    {
116 108
      // if the free block within 20 bytes of the size you want
117 109
      // simply mark it occupied and return it
118

  
119 110
      if (tmp->size <= bytes_needed + 50)
120 111
      {
121 112
        tmp->status = 1;
......
124 115
        
125 116
	temp_ptr = gradient_structure::ARRAY_MEMBLOCK_BASE + tmp->offset;
126 117

  
127
	(* (arr_link **) (temp_ptr)) = tmp; //put the address
128
					  //tmp into the location pointed to
129
					  //by temp_ptr
130
	return  (double_and_int *) (temp_ptr);
118
	//put the address tmp into the location pointed to by temp_ptr
119
	(* (arr_link **) (temp_ptr)) = tmp;
120

  
121
	return (double_and_int*)temp_ptr;
131 122
      }
132 123
      else
133 124
      {
134
	// otherwise split up this memory block and return
135
	// the part you need
125
	// otherwise split up this memory block and return the part you need
126
	arr_link* tmp1 = new arr_link();
127
        gradient_structure::ARR_LIST1->number_arr_links++;
136 128

  
137
	arr_link * tmp1 = new arr_link;
138
        gradient_structure::ARR_LIST1->number_arr_links += 1;
139

  
140 129
        // put the new link tmp1-> into the list BEFORE tmp->
141

  
142 130
        tmp1->prev=tmp->prev;
143

  
144
        if(tmp1->prev)
131
        if (tmp1->prev)
145 132
        {
146 133
          tmp1->prev->next=tmp1;
147 134
        }
148

  
149 135
        tmp1->next=tmp;
150 136
        tmp->prev=tmp1;
151 137

  
152 138
        // get the size of the new link and mark it free
153

  
154 139
        tmp1->size=bytes_needed;
155 140
	tmp1->status=1;
156 141
        tmp1->offset=tmp->offset;
......
160 145

  
161 146
	temp_ptr = gradient_structure::ARRAY_MEMBLOCK_BASE + tmp1->offset;
162 147

  
163
	(* (arr_link **) (temp_ptr )) = tmp1; //put the address
164
					 //pointed to by
165
					 // tmp1 into the location pointed to
166
					 //by temp_ptr
167
	return  (double_and_int *) (temp_ptr);
148
	//put the address pointed to by  tmp1 into the location pointed to by temp_ptr
149
	(* (arr_link **) (temp_ptr )) = tmp1;
150

  
151
	return (double_and_int*)temp_ptr;
168 152
      }
169 153
    }
170 154
    tmp=tmp->free_prev;
171 155
  }
172
  // couldn't find a free block large enough
173
  // make a new block
174

  
175
  tmp = new arr_link;
176
  if (tmp==0)
156
  //couldn't find a free block large enough.  make a new block
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff