示例#1
0
/*! \brief Allocate and initialize a complex vector
 *  \param[in] len The buffer length in complex samples
 *  \param[in] start Starting index for useful data
 *  \param[in] buf Pointer to a pre-existing buffer
 *  \param[in] flags Flags for various vector attributes
 *
 *  If buf is NULL, then a buffer will be allocated.
 */
struct cxvec *cxvec_alloc(int len, int start, float complex *buf, int flags)
{
	struct cxvec *vec;

	/* Disallow zero length data */
	if ((start >= len) || (len <= 0) || (start < 0)) {
		fprintf(stderr, "cxvec_alloc: invalid input\n");
		return NULL;
	}

	vec = (struct cxvec *) malloc(sizeof(struct cxvec));

	if (!buf) {
		if (flags & CXVEC_FLG_MEM_ALIGN)
			buf = (float complex *) memalign(ALIGN_SZ, sizeof(float complex) * len);
		else if (flags & CXVEC_FLG_FFT_ALIGN)
			buf = (float complex *) fft_malloc(sizeof(float complex) * len);
		else
			buf = (float complex *) malloc(sizeof(float complex) * len);
	} else {
		flags |= CXVEC_FLG_MEM_CHILD;
	}

	cxvec_init(vec, len - start, len, start, buf, flags);

	return vec;
}
示例#2
0
文件: mem.c 项目: junkoda/fs
void mem_alloc_reserved(Mem* const mem)
{
  if(mem->buf) free(mem->buf);

  mem->buf= fft_malloc(mem->size_using);

  if(mem->buf == 0)
    msg_abort("Error: Unable to allocate %lu MB for %s\n",
	      mem->size_using/(1024*1024), mem->name);
  else
    msg_printf(msg_info, "%lu MB allocated for mem %s\n",
	       mem->size_using/(1024*1024), mem->name);

  mem->size_alloc= mem->size_using;
  mem->size_using= 0;
}