Skip to content

Commit

Permalink
Merge pull request #1423 from oicchris/release/4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dellaert authored Jan 28, 2023
2 parents 88b4082 + a7b42dc commit ee63a5b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions gtsam/nonlinear/Expression-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

#pragma once

// The MSVC compiler workaround for the unsupported variable length array
// utilizes the std::unique_ptr<> custom deleter.
// See Expression<T>::valueAndJacobianMap() below.
#ifdef _MSC_VER
#include <memory>
#endif

#include <gtsam/nonlinear/internal/ExpressionNode.h>

#include <boost/bind/bind.hpp>
Expand Down Expand Up @@ -208,7 +215,10 @@ T Expression<T>::valueAndJacobianMap(const Values& values,
// allocated on Visual Studio. For more information see the issue below
// https://bitbucket.org/gtborg/gtsam/issue/178/vlas-unsupported-in-visual-studio
#ifdef _MSC_VER
auto traceStorage = static_cast<internal::ExecutionTraceStorage*>(_aligned_malloc(size, internal::TraceAlignment));
std::unique_ptr<void, void(*)(void*)> traceStorageDeleter(
_aligned_malloc(size, internal::TraceAlignment),
[](void *ptr){ _aligned_free(ptr); });
auto traceStorage = static_cast<internal::ExecutionTraceStorage*>(traceStorageDeleter.get());
#else
internal::ExecutionTraceStorage traceStorage[size];
#endif
Expand All @@ -217,10 +227,6 @@ T Expression<T>::valueAndJacobianMap(const Values& values,
T value(this->traceExecution(values, trace, traceStorage));
trace.startReverseAD1(jacobians);

#ifdef _MSC_VER
_aligned_free(traceStorage);
#endif

return value;
}

Expand Down

0 comments on commit ee63a5b

Please sign in to comment.