vrpRouting  0.3
pgr_alloc.hpp File Reference
#include <string>
Include dependency graph for pgr_alloc.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename T >
T * pgr_alloc (std::size_t size, T *ptr)
 allocates memory More...
 
template<typename T >
T * pgr_free (T *ptr)
 
char * pgr_msg (const std::string &msg)
 
void * SPI_palloc (size_t size)
 
void SPI_pfree (void *pointer)
 
void * SPI_repalloc (void *pointer, size_t size)
 

Function Documentation

◆ pgr_alloc()

template<typename T >
pgr_alloc ( std::size_t  size,
T *  ptr 
)

allocates memory

  • Does a malloc or realloc depending on the ptr value
  • To be used only on C++ code
  • To be used when returning results to postgres
  • free must occur in the C code
Parameters
[in]size
[in]ptr
Returns
pointer to the first byte of allocated space

Definition at line 66 of file pgr_alloc.hpp.

66  {
67  if (!ptr) {
68  ptr = static_cast<T*>(SPI_palloc(size * sizeof(T)));
69  } else {
70  ptr = static_cast<T*>(SPI_repalloc(ptr, size * sizeof(T)));
71  }
72  return ptr;
73 }

References SPI_palloc(), and SPI_repalloc().

Referenced by do_compatibleVehicles(), do_optimize(), do_pgr_pickDeliver(), do_pgr_pickDeliverEuclidean(), do_pickDeliver(), do_vrp_vroom(), and pgr_msg().

◆ pgr_free()

template<typename T >
T* pgr_free ( T *  ptr)

Definition at line 77 of file pgr_alloc.hpp.

77  {
78  if (ptr) {
79  SPI_pfree(ptr);
80  }
81  return nullptr;
82 }

References SPI_pfree().

Referenced by do_vrp_vroom().

◆ pgr_msg()

char* pgr_msg ( const std::string &  msg)

Definition at line 33 of file pgr_alloc.cpp.

33  {
34  char* duplicate = nullptr;
35  duplicate = pgr_alloc(msg.size() + 1, duplicate);
36  memcpy(duplicate, msg.c_str(), msg.size());
37  duplicate[msg.size()] = '\0';
38  return duplicate;
39 }

References pgr_alloc().

Referenced by do_compatibleVehicles(), do_optimize(), do_pgr_pickDeliver(), do_pgr_pickDeliverEuclidean(), do_pickDeliver(), and do_vrp_vroom().

◆ SPI_palloc()

void* SPI_palloc ( size_t  size)

Referenced by pgr_alloc().

◆ SPI_pfree()

void SPI_pfree ( void *  pointer)

Referenced by pgr_free().

◆ SPI_repalloc()

void* SPI_repalloc ( void *  pointer,
size_t  size 
)

Referenced by pgr_alloc().

pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
SPI_repalloc
void * SPI_repalloc(void *pointer, size_t size)
SPI_pfree
void SPI_pfree(void *pointer)
SPI_palloc
void * SPI_palloc(size_t size)