04-17-2005, 06:38 PM
Go to the plantasy site, get memProcs
Use it..
If you dont want to use memProcs, hange mem_alloc to: callocate()
And mem_cleanup to: deallocate memptr
To reallocate:
memptr = mem_realloc(memptr, new_size)
Or:
memptr = reallocate(memptr, new_size)
The advantage of using memProcs is, apart from offering more functions, that it keeps track of allocated memory, and you only have to call mem_cleanup to free everything you allocated, as opposed to having to add a new deallocate for each allocate.
Use it..
Code:
type mytype
arr2 as uinteger ptr
end type
dim arr1(1000) as mytype
arr1(0).arr2 = mem_alloc(1024) 'allocate 1024 bytes
arr1(1).arr2 = mem_alloc(1024) 'allocate 1024 bytes
arr1(0).arr2[0] = 1000
arr1(0).arr2[1] = 2000
arr1(0).arr2[2] = 3000
arr1(1).arr2[0] = 11000
arr1(1).arr2[1] = 12000
arr1(1).arr2[2] = 13000
print arr1(0).arr2[1] 'prints 2000
print arr1(1).arr2[1] 'prints 12000
mem_cleanup 'free all allocated memory
If you dont want to use memProcs, hange mem_alloc to: callocate()
And mem_cleanup to: deallocate memptr
Code:
type mytype
arr2 as uinteger ptr
end type
dim arr1(1000) as mytype
arr1(0).arr2 = callocate(1024) 'allocate 1024 bytes
arr1(1).arr2 = callocate(1024) 'allocate 1024 bytes
arr1(0).arr2[0] = 1000
arr1(0).arr2[1] = 2000
arr1(0).arr2[2] = 3000
arr1(1).arr2[0] = 11000
arr1(1).arr2[1] = 12000
arr1(1).arr2[2] = 13000
print arr1(0).arr2[1] 'prints 2000
print arr1(1).arr2[1]+arr1(1).arr2[0] 'prints 23000 (12000+11000)
deallocate arr1(0).arr2 'free all allocated memory
deallocate arr1(1).arr2
To reallocate:
memptr = mem_realloc(memptr, new_size)
Or:
memptr = reallocate(memptr, new_size)
The advantage of using memProcs is, apart from offering more functions, that it keeps track of allocated memory, and you only have to call mem_cleanup to free everything you allocated, as opposed to having to add a new deallocate for each allocate.