Revision 1176 branches/threaded2merge/src/linad99/newdar.cpp

newdar.cpp (revision 1176)
78 78
 * Description not yet available.
79 79
 * \param
80 80
 */
81
double_and_int * arr_new(unsigned int sz)
81
double_and_int* arr_new(unsigned int sz)
82 82
{
83 83
  if (!gradient_structure::instances)
84 84
  {
......
88 88
    ad_exit(1);
89 89
  }
90 90

  
91
  char * temp_ptr;
91
  char* temp_ptr = 0;
92 92

  
93 93
  // this routine allocated a block of memory of sizeof(double)*sz bytes
94 94
  // for the gradients of an array or matrix of prevariables
95 95

  
96
  arr_link * tmp = gradient_structure::ARR_LIST1->free_last;
96
  arr_link* tmp = gradient_structure::ARR_LIST1->free_last;
97 97

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

  
100
/*
99 101
  int ss=0;
100 102
  if (ss)
101 103
  {
102 104
    double_and_int * tt=0;
103 105
    return tt;
104 106
  }
107
*/
105 108

  
106 109
  while (tmp)
107 110
  {
......
109 112
    {
110 113
      // if the free block within 20 bytes of the size you want
111 114
      // simply mark it occupied and return it
112

  
113 115
      if (tmp->size <= bytes_needed + 50)
114 116
      {
115 117
        tmp->status = 1;
118

  
116 119
        // remove tmp from the free list
117 120
        arr_free_remove(tmp);
118 121

  
119 122
	temp_ptr = gradient_structure::ARRAY_MEMBLOCK_BASE + tmp->offset;
120 123

  
121
	(* (arr_link **) (temp_ptr)) = tmp; //put the address
122
					  //tmp into the location pointed to
123
					  //by temp_ptr
124
	return  (double_and_int *) (temp_ptr);
124
        //put the address tmp into the location pointed to by temp_ptr
125
	(*(arr_link**)(temp_ptr)) = tmp;
126

  
127
	return (double_and_int*)temp_ptr;
125 128
      }
126 129
      else
127 130
      {
128 131
	// otherwise split up this memory block and return
129 132
	// the part you need
130

  
131
	arr_link * tmp1 = new arr_link;
133
	arr_link* tmp1 = new arr_link();
132 134
        gradient_structure::ARR_LIST1->number_arr_links += 1;
133 135

  
134 136
        // put the new link tmp1-> into the list BEFORE tmp->
135

  
136 137
        tmp1->prev=tmp->prev;
137 138

  
138 139
        if(tmp1->prev)
......
144 145
        tmp->prev=tmp1;
145 146

  
146 147
        // get the size of the new link and mark it free
147

  
148 148
        tmp1->size=bytes_needed;
149 149
	tmp1->status=1;
150 150
        tmp1->offset=tmp->offset;
......
154 154

  
155 155
	temp_ptr = gradient_structure::ARRAY_MEMBLOCK_BASE + tmp1->offset;
156 156

  
157
	(* (arr_link **) (temp_ptr )) = tmp1; //put the address
158
					 //pointed to by
159
					 // tmp1 into the location pointed to
160
					 //by temp_ptr
157
        //put the address pointed to by tmp1 into the location pointed to by temp_ptr
158
	(* (arr_link **) (temp_ptr )) = tmp1;
159

  
161 160
	return  (double_and_int *) (temp_ptr);
162 161
      }
163 162
    }
164 163
    tmp=tmp->free_prev;
165 164
  }
166
  // couldn't find a free block large enough
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff