blob: dff30b7cd27fae8d168824859b4d35da18b89dfe [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001// This may look like C code, but it is really -*- C++ -*-
2//
3// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2004
4//
5// Implementation of Blob
6//
7
8#define MAGICKCORE_IMPLEMENTATION 1
9#define MAGICK_PLUSPLUS_IMPLEMENTATION 1
10
cristy05065f42011-09-08 01:11:30 +000011#include <cstring>
cristy3ed852e2009-09-05 21:47:34 +000012#include "Magick++/Include.h"
13#include "Magick++/Thread.h"
14#include "Magick++/BlobRef.h"
15
16#include <string.h>
17
18//
19// Implementation of Magick::BlobRef
20//
21
22// Construct with data, making private copy of data
23Magick::BlobRef::BlobRef ( const void* data_,
24 size_t length_ )
25 : _data(0),
26 _length(length_),
27 _allocator(Magick::Blob::NewAllocator),
28 _refCount(1),
29 _mutexLock()
30{
31 if( data_ )
32 {
33 _data = new unsigned char[length_];
cristy05065f42011-09-08 01:11:30 +000034 memcpy( _data, data_, length_ );
cristy3ed852e2009-09-05 21:47:34 +000035 }
36}
37
38// Destructor (actually destroys data)
39Magick::BlobRef::~BlobRef ( void )
40{
41 if ( _allocator == Magick::Blob::NewAllocator )
42 {
43 delete [] static_cast<unsigned char*>(_data);
44 _data=0;
45 }
46 else if ( _allocator == Magick::Blob::MallocAllocator )
47 {
48 _data=(void *) RelinquishMagickMemory(_data);
49 }
50}