Magick++ 6.9.13
Loading...
Searching...
No Matches
BlobRef.cpp
1// This may look like C code, but it is really -*- C++ -*-
2//
3// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2004
4// Copyright Dirk Lemstra 2015
5//
6// Implementation of Blob
7//
8
9#define MAGICKCORE_IMPLEMENTATION 1
10#define MAGICK_PLUSPLUS_IMPLEMENTATION 1
11
12#include "Magick++/Include.h"
13#include "Magick++/Thread.h"
14#include "Magick++/BlobRef.h"
15
16#include <string.h>
17
18Magick::BlobRef::BlobRef(const void* data_,const size_t length_)
19 : _data(0),
20 _length(length_),
21 _allocator(Magick::Blob::NewAllocator),
22 _refCount(1),
23 _mutexLock()
24{
25 if (data_)
26 {
27 _data=new unsigned char[length_];
28 memcpy(_data,data_,length_);
29 }
30}
31
32// Destructor (actually destroys data)
33Magick::BlobRef::~BlobRef(void)
34{
35 if (_allocator == Magick::Blob::NewAllocator)
36 {
37 delete[] static_cast<unsigned char*>(_data);
38 _data=0;
39 }
40 else if (_allocator == Magick::Blob::MallocAllocator)
41 {
42 _data=(void *) RelinquishMagickMemory(_data);
43 }
44}