GSL的引用手册中写道
The pointer block stores the location of the memory block in which the vector elements are located (if any). If the vector owns this block then the owner field is set to one and the block will be deallocated when the vector is freed.
但是“如果向量拥有该 block ”是什么意思?
以下是gsl_vector的结构体
typedef struct
{
size_t size;
size_t stride;
double * data;
gsl_block * block;
int owner;
} gsl_vector;
最佳答案
根据文档:
For consistency all memory is allocated through a gsl_block structure.
下一个:
Vectors and matrices are made by slicing an underlying block.
基本上,您可以使用现有的内存块来获取新的向量,例如使用(由于某种原因未记录的)函数alloc_from_block
或alloc_from_vector
。在这种情况下,owner
设置为 0,并且当您释放初始 block 保持分配状态的向量时:
void
FUNCTION (gsl_vector, free) (TYPE (gsl_vector) * v)
{
RETURN_IF_NULL (v);
if (v->owner)
{
FUNCTION(gsl_block, free) (v->block) ;
}
free (v);
}
关于gsl - gsl_vector 如何拥有 gsl_block?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54291867/