Skip to content

Commit

Permalink
Moving to char vectors instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jrenaud90 committed Nov 30, 2024
1 parent 21939ec commit 5fdd805
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 35 deletions.
43 changes: 12 additions & 31 deletions CyRK/cy/cysolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,18 @@ CySolverBase::CySolverBase(
{
// Allocate memory for the size of args.
// Store void pointer to it.
printf("Pre Malloc\n");
this->args_char_ptr = new char[size_of_args];

if (this->args_char_ptr)
{
this->args_built = true;
this->args_ptr = (void*)this->args_char_ptr;
// Copy over contents of arg
printf("Pre Copy Over\n");
std::memcpy(this->args_ptr, args_ptr, size_of_args);
printf("Post\n");
}
else
{
// TODO: Memory error?
this->storage_sptr->error_code = -870;
}
printf("Pre resize\n");
this->args_char_vec.resize(size_of_args);

this->args_ptr = (void*)this->args_char_vec.data();
// Copy over contents of arg
printf("Pre Copy Over\n");
std::memcpy(this->args_ptr, args_ptr, size_of_args);
printf("Post\n");
}
else
{
this->args_ptr = nullptr;
}

// Check for errors
Expand Down Expand Up @@ -185,20 +180,6 @@ CySolverBase::~CySolverBase()
{
this->storage_sptr.reset();
}

// Release args data
if (this->args_built)
{
printf("Deconstructor:: args built.\n");
if (this->args_char_ptr)
{
printf("Deconstructor:: args array not null.\n");
delete[] this->args_char_ptr;
printf("Deconstructor:: args deleted.\n");
this->args_char_ptr = nullptr;
this->args_ptr = nullptr;
}
}
}

// Protected methods
Expand Down
10 changes: 6 additions & 4 deletions CyRK/cy/cysolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstring>

#include <vector>
#include <algorithm>
#include <functional>
#include <memory>
Expand Down Expand Up @@ -105,10 +106,11 @@ class CySolverBase {
// Integration step information
size_t max_num_steps = 0;

// Differential equation information
void* args_ptr = nullptr;
char* args_char_ptr = nullptr;
bool args_built = false;
// Additional arguments for the diffeq are stored locally in a char dynamic vector.
std::vector<char> args_char_vec = std::vector<char>();
void* args_ptr = nullptr;

// Differential equation information
DiffeqFuncType diffeq_ptr = nullptr;

// t_eval information
Expand Down

0 comments on commit 5fdd805

Please sign in to comment.