gsl - gsl_vector 如何拥有 gsl_block?

标签 gsl

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_blockalloc_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/

相关文章:

c++ - 线程安全函数指针 gsl 蒙特卡洛积分

c - 将 GSL 库链接到 Matlab MEX 时如何修复 'unknown type name' 错误

c - 如何定义全局 gsl_vector

c++ - 转换 gsl 线性代数以在 scalapack 或其他并行矩阵库中使用

c - 通过 c 包装器使用 Gnu 科学图书馆的 Fortran 程序没有输出

C++:将 std::function 转换为 gsl_function

c - 使用 C 访问 GSL 库

c++ - 创建对象 vector 以使用 GSL 求解 ODE 时出现段错误

c++ - 对 `gsl_vector_free' 的 undefined reference

c++ - 在 C++ 中使用 GSL 蒙特卡罗积分求解多维函数