本文整理汇总了C++中HeapBlock类的典型用法代码示例。如果您正苦于以下问题:C++ HeapBlock类的具体用法?C++ HeapBlock怎么用?C++ HeapBlock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HeapBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: jassert
bool AudioFormatWriter::writeFromAudioSampleBuffer (const AudioSampleBuffer& source, int startSample, int numSamples)
{
jassert (startSample >= 0 && startSample + numSamples <= source.getNumSamples() && source.getNumChannels() > 0);
if (numSamples <= 0)
return true;
HeapBlock<int> tempBuffer;
HeapBlock<int*> chans (numChannels + 1);
chans [numChannels] = 0;
if (isFloatingPoint())
{
for (int i = (int) numChannels; --i >= 0;)
chans[i] = reinterpret_cast<int*> (source.getSampleData (i, startSample));
}
else
{
tempBuffer.malloc (numSamples * numChannels);
for (unsigned int i = 0; i < numChannels; ++i)
{
typedef AudioData::Pointer <AudioData::Int32, AudioData::NativeEndian, AudioData::NonInterleaved, AudioData::NonConst> DestSampleType;
typedef AudioData::Pointer <AudioData::Float32, AudioData::NativeEndian, AudioData::NonInterleaved, AudioData::Const> SourceSampleType;
DestSampleType destData (chans[i] = tempBuffer + i * numSamples);
SourceSampleType sourceData (source.getSampleData ((int) i, startSample));
destData.convertSamples (sourceData, numSamples);
}
}
return write ((const int**) chans.getData(), numSamples);
}
示例2: getNumChannels
static int getNumChannels (AudioDeviceID deviceID, bool input)
{
int total = 0;
UInt32 size;
AudioObjectPropertyAddress pa;
pa.mSelector = kAudioDevicePropertyStreamConfiguration;
pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
pa.mElement = kAudioObjectPropertyElementMaster;
if (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr)
{
HeapBlock <AudioBufferList> bufList;
bufList.calloc (size, 1);
if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList) == noErr)
{
const int numStreams = bufList->mNumberBuffers;
for (int i = 0; i < numStreams; ++i)
{
const AudioBuffer& b = bufList->mBuffers[i];
total += b.mNumberChannels;
}
}
}
return total;
}
示例3: buf
void OutputStream::printf (const char* pf, ...)
{
unsigned int bufSize = 256;
HeapBlock <char> buf (bufSize);
for (;;)
{
va_list list;
va_start (list, pf);
const int num = CharacterFunctions::vprintf (buf, bufSize, pf, list);
va_end (list);
if (num > 0)
{
write (buf, num);
break;
}
else if (num == 0)
{
break;
}
bufSize += 256;
buf.malloc (bufSize);
}
}
示例4: juce_handleSelectionRequest
//==============================================================================
// Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
{
ClipboardHelpers::initSelectionAtoms();
// the selection content is sent to the target window as a window property
XSelectionEvent reply;
reply.type = SelectionNotify;
reply.display = evt.display;
reply.requestor = evt.requestor;
reply.selection = evt.selection;
reply.target = evt.target;
reply.property = None; // == "fail"
reply.time = evt.time;
HeapBlock <char> data;
int propertyFormat = 0, numDataItems = 0;
if (evt.selection == XA_PRIMARY || evt.selection == ClipboardHelpers::atom_CLIPBOARD)
{
if (evt.target == XA_STRING || evt.target == ClipboardHelpers::atom_UTF8_STRING)
{
// translate to utf8
numDataItems = ClipboardHelpers::localClipboardContent.getNumBytesAsUTF8() + 1;
data.calloc (numDataItems + 1);
ClipboardHelpers::localClipboardContent.copyToUTF8 (data, numDataItems);
propertyFormat = 8; // bits/item
}
else if (evt.target == ClipboardHelpers::atom_TARGETS)
{
// another application wants to know what we are able to send
numDataItems = 2;
propertyFormat = 32; // atoms are 32-bit
data.calloc (numDataItems * 4);
Atom* atoms = reinterpret_cast<Atom*> (data.getData());
atoms[0] = ClipboardHelpers::atom_UTF8_STRING;
atoms[1] = XA_STRING;
}
}
else
{
DBG ("requested unsupported clipboard");
}
if (data != nullptr)
{
const int maxReasonableSelectionSize = 1000000;
// for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
if (evt.property != None && numDataItems < maxReasonableSelectionSize)
{
XChangeProperty (evt.display, evt.requestor,
evt.property, evt.target,
propertyFormat /* 8 or 32 */, PropModeReplace,
reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
reply.property = evt.property; // " == success"
}
}
XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
}
示例5: Assert
//=====================================================================================================
// Free
//=====================================================================================================
void
LargeHeapBucket::ExplicitFree(void * object, size_t sizeCat)
{
Assert(HeapInfo::GetMediumObjectAlignedSizeNoCheck(sizeCat) == this->sizeCat);
LargeObjectHeader * header = LargeHeapBlock::GetHeaderFromAddress(object);
Assert(header->GetAttributes(this->heapInfo->recycler->Cookie) == ObjectInfoBits::NoBit || header->GetAttributes(this->heapInfo->recycler->Cookie) == ObjectInfoBits::LeafBit);
Assert(!header->isExplicitFreed);
DebugOnly(header->isExplicitFreed = true);
Assert(header->objectSize >= sizeCat);
#if DBG
HeapBlock* heapBlock = this->GetRecycler()->FindHeapBlock(object);
Assert(heapBlock != nullptr);
Assert(heapBlock->IsLargeHeapBlock());
LargeHeapBlock * largeHeapBlock = (LargeHeapBlock *)heapBlock;
LargeObjectHeader * dbgHeader;
Assert(largeHeapBlock->GetObjectHeader(object, &dbgHeader));
Assert(dbgHeader == header);
#endif
FreeObject * freeObject = (FreeObject *)object;
freeObject->SetNext(this->explicitFreeList);
this->explicitFreeList = freeObject;
header->SetAttributes(this->heapInfo->recycler->Cookie, ObjectInfoBits::LeafBit); // We can stop scanning it now.
}
示例6: update
static ptr update( const ptr &p, const HeapBlock *const &oldP, const InitData &id ) {
HeapBlock *t = (HeapBlock*)p;
if( t != oldP ) {
t->fix(id);
} else t->Size = id.RequiredMemory(); //leave the callstack as is, err.. easier, other wise we may have to realllocate
return t->retPtr();
}
示例7: mem
ID3D11Texture2D* D3D11Context::createTexture2DFromAppData (const char* id)
{
int dataSize;
const char* data = demo_->appDataGet (id, dataSize);
if (nullptr == data)
return nullptr;
juce::Image img = ImageCache::getFromMemory (data, dataSize);
if (!img.isValid())
return nullptr;
int w = img.getWidth();
int h = img.getHeight();
if ((w % 2) > 0 || (h % 2) > 0)
{
w = (w % 2) > 0 ? (w + 1) : w;
h = (h % 2) > 0 ? (h + 1) : h;
img = img.rescaled (w, h);
}
img = img.convertedToFormat (juce::Image::ARGB);
HeapBlock<uint8> mem (w * h * 4);
memset (mem.getData(), 0xff, w * h * 4);
juce::Image::BitmapData imgData (img, juce::Image::BitmapData::readOnly);
uint8* src = imgData.data;
uint8* dst = mem.getData();
size_t rowPitch = (size_t)w * 4;
for (int r = 0; r < h; ++r)
{
uint8* s = src;
uint8* d = dst;
for (int c = 0; c < w; ++c)
{
d[0] = s[2];
d[1] = s[1];
d[2] = s[0];
d[3] = s[3];
s += 4;
d += 4;
}
src += imgData.lineStride;
dst += rowPitch;
}
Hold<ID3D11Texture2D> texture;
if (texture.set (createTexture2D (w, h, 1, DXGI_FORMAT_R8G8B8A8_UNORM, mem.getData(), rowPitch, h * rowPitch)).isNull())
return nullptr;
return texture.drop();
}
示例8: source
bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
{
if (audioSource == 0)
return false;
ScopedPointer<AudioSource> source (audioSource);
long bytesPerBlock;
HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
const int samplesPerBlock = bytesPerBlock / 4;
bool ok = true;
hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
HeapBlock <byte> buffer (bytesPerBlock);
AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
int samplesDone = 0;
source->prepareToPlay (samplesPerBlock, 44100.0);
while (ok)
{
{
AudioSourceChannelInfo info;
info.buffer = &sourceBuffer;
info.numSamples = samplesPerBlock;
info.startSample = 0;
sourceBuffer.clear();
source->getNextAudioBlock (info);
}
buffer.clear (bytesPerBlock);
typedef AudioData::Pointer <AudioData::Int16, AudioData::LittleEndian,
AudioData::Interleaved, AudioData::NonConst> CDSampleFormat;
typedef AudioData::Pointer <AudioData::Float32, AudioData::NativeEndian,
AudioData::NonInterleaved, AudioData::Const> SourceSampleFormat;
CDSampleFormat left (buffer, 2);
left.convertSamples (SourceSampleFormat (sourceBuffer.getSampleData (0)), samplesPerBlock);
CDSampleFormat right (buffer + 2, 2);
right.convertSamples (SourceSampleFormat (sourceBuffer.getSampleData (1)), samplesPerBlock);
hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
if (FAILED (hr))
ok = false;
samplesDone += samplesPerBlock;
if (samplesDone >= numSamples)
break;
}
hr = pimpl->redbook->CloseAudioTrack();
return ok && hr == S_OK;
}
示例9: mach_absolute_time
void MidiOutput::sendMessageNow (const MidiMessage& message)
{
#if JUCE_IOS
const MIDITimeStamp timeStamp = mach_absolute_time();
#else
const MIDITimeStamp timeStamp = AudioGetCurrentHostTime();
#endif
HeapBlock<MIDIPacketList> allocatedPackets;
MIDIPacketList stackPacket;
MIDIPacketList* packetToSend = &stackPacket;
const size_t dataSize = (size_t) message.getRawDataSize();
if (message.isSysEx())
{
const int maxPacketSize = 256;
int pos = 0, bytesLeft = (int) dataSize;
const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
allocatedPackets.malloc ((size_t) (32 * (size_t) numPackets + dataSize), 1);
packetToSend = allocatedPackets;
packetToSend->numPackets = (UInt32) numPackets;
MIDIPacket* p = packetToSend->packet;
for (int i = 0; i < numPackets; ++i)
{
p->timeStamp = timeStamp;
p->length = (UInt16) jmin (maxPacketSize, bytesLeft);
memcpy (p->data, message.getRawData() + pos, p->length);
pos += p->length;
bytesLeft -= p->length;
p = MIDIPacketNext (p);
}
}
else if (dataSize < 65536) // max packet size
{
const size_t stackCapacity = sizeof (stackPacket.packet->data);
if (dataSize > stackCapacity)
{
allocatedPackets.malloc ((sizeof (MIDIPacketList) - stackCapacity) + dataSize, 1);
packetToSend = allocatedPackets;
}
packetToSend->numPackets = 1;
MIDIPacket& p = *(packetToSend->packet);
p.timeStamp = timeStamp;
p.length = (UInt16) dataSize;
memcpy (p.data, message.getRawData(), dataSize);
}
else
{
jassertfalse; // packet too large to send!
return;
}
static_cast<CoreMidiHelpers::MidiPortAndEndpoint*> (internal)->send (packetToSend);
}
示例10: GetSizeForPtr
int MultiHeap::GetSizeForPtr(void* pObj)
{
HeapBlock* pBlock = HeapBlock::ObjPointerToHeapBlock(pObj);
if (pBlock == 0)
return -1;
return pBlock->GetObjSize();
}
示例11: printAll
static void printAll(bool unloadSymbolsAfter) {
if(Last) {
SymbolMan sm(unloadSymbolsAfter);
for( HeapBlock* h = Last; h; h = h->Prev ) h->print(sm);
Beep( 8000, 400 );
Beep( 4000, 500 );
}
}
示例12: scanForDevices
//==============================================================================
void scanForDevices()
{
hasScanned = true;
inputDeviceNames.clear();
outputDeviceNames.clear();
inputIds.clear();
outputIds.clear();
UInt32 size;
AudioObjectPropertyAddress pa;
pa.mSelector = kAudioHardwarePropertyDevices;
pa.mScope = kAudioObjectPropertyScopeWildcard;
pa.mElement = kAudioObjectPropertyElementMaster;
if (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size) == noErr)
{
HeapBlock <AudioDeviceID> devs;
devs.calloc (size, 1);
if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs) == noErr)
{
const int num = size / (int) sizeof (AudioDeviceID);
for (int i = 0; i < num; ++i)
{
char name [1024];
size = sizeof (name);
pa.mSelector = kAudioDevicePropertyDeviceName;
if (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name) == noErr)
{
const String nameString (String::fromUTF8 (name, (int) strlen (name)));
const int numIns = getNumChannels (devs[i], true);
const int numOuts = getNumChannels (devs[i], false);
if (numIns > 0)
{
inputDeviceNames.add (nameString);
inputIds.add (devs[i]);
}
if (numOuts > 0)
{
outputDeviceNames.add (nameString);
outputIds.add (devs[i]);
}
}
}
}
}
inputDeviceNames.appendNumbersToDuplicates (false, true);
outputDeviceNames.appendNumbersToDuplicates (false, true);
}
示例13: findLongestCommonSubstring
static int findLongestCommonSubstring (String::CharPointerType a, const int lenA,
const String::CharPointerType b, const int lenB,
int& indexInA, int& indexInB)
{
if (lenA == 0 || lenB == 0)
return 0;
HeapBlock<int> lines;
lines.calloc (2 + 2 * (size_t) lenB);
int* l0 = lines;
int* l1 = l0 + lenB + 1;
int loopsWithoutImprovement = 0;
int bestLength = 0;
indexInA = indexInB = 0;
for (int i = 0; i < lenA; ++i)
{
const juce_wchar ca = a.getAndAdvance();
String::CharPointerType b2 (b);
for (int j = 0; j < lenB; ++j)
{
if (ca != b2.getAndAdvance())
{
l1[j + 1] = 0;
}
else
{
const int len = l0[j] + 1;
l1[j + 1] = len;
if (len > bestLength)
{
loopsWithoutImprovement = 0;
bestLength = len;
indexInA = i;
indexInB = j;
}
}
}
if (++loopsWithoutImprovement > 100)
break;
std::swap (l0, l1);
}
indexInA -= bestLength - 1;
indexInB -= bestLength - 1;
return bestLength;
}
示例14: GetCurrentProcess
//==============================================================================
String SystemStats::getStackBacktrace()
{
String result;
#if JUCE_ANDROID || JUCE_MINGW || JUCE_HAIKU
jassertfalse; // sorry, not implemented yet!
#elif JUCE_WINDOWS
HANDLE process = GetCurrentProcess();
SymInitialize (process, nullptr, TRUE);
void* stack[128];
int frames = (int) CaptureStackBackTrace (0, numElementsInArray (stack), stack, nullptr);
HeapBlock<SYMBOL_INFO> symbol;
symbol.calloc (sizeof (SYMBOL_INFO) + 256, 1);
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof (SYMBOL_INFO);
for (int i = 0; i < frames; ++i)
{
DWORD64 displacement = 0;
if (SymFromAddr (process, (DWORD64) stack[i], &displacement, symbol))
{
result << i << ": ";
IMAGEHLP_MODULE64 moduleInfo;
zerostruct (moduleInfo);
moduleInfo.SizeOfStruct = sizeof (moduleInfo);
if (::SymGetModuleInfo64 (process, symbol->ModBase, &moduleInfo))
result << moduleInfo.ModuleName << ": ";
result << symbol->Name << " + 0x" << String::toHexString ((int64) displacement) << newLine;
}
}
#else
void* stack[128];
int frames = backtrace (stack, numElementsInArray (stack));
char** frameStrings = backtrace_symbols (stack, frames);
for (int i = 0; i < frames; ++i)
result << frameStrings[i] << newLine;
::free (frameStrings);
#endif
return result;
}
示例15: receive
void receive (jbyteArray byteArray, jlong offset, jint len, jlong timestamp)
{
jassert (byteArray != nullptr);
jbyte* data = getEnv()->GetByteArrayElements (byteArray, nullptr);
HeapBlock<uint8> buffer (len);
std::memcpy (buffer.getData(), data + offset, len);
midiConcatenator.pushMidiData (buffer.getData(),
len, static_cast<double> (timestamp) * 1.0e-9,
juceMidiInput, *callback);
getEnv()->ReleaseByteArrayElements (byteArray, data, 0);
}