Click here to Skip to main content
15,884,237 members
Articles / Desktop Programming / WTL

Multidevice ASIO output plugin for WinAMP

Rate me:
Please Sign up or sign in to vote.
4.80/5 (9 votes)
13 Feb 2009CDDL27 min read 48.1K   728   23  
A tiny WinAMP output DLL that uses a C++ replacement of the official ASIO SDK that supports multiple ASIO devices.
// alloc.cpp

// based on:
// LIBCTINY - Matt Pietrek 2001
// MSDN Magazine, January 2001

// 08/12/06 (mv)


// Modified without permission by Domagoj �ari� (dsaritz at gmail . com ).
// 02/05/09


#include <windows.h>
#include <malloc.h>
#include <cassert>
#include "libct.h"


//  For 'native' long long arithmetic on 32 bit machines add these to the link:
// llmul.obj lldiv.obj llshl.obj llshr.obj ulldiv.obj
// #pragma comment(lib, "lldiv.obj")

//  For runtime checks, alloca and exceptions add these to the link:
// RunTmChk.lib chkstk.obj


HANDLE getLowFragmentationHeap()
{
    HANDLE const hLocalProcessHeap( ::GetProcessHeap() );
    ULONG useLowFragmentationHeapFlag( 2 );
    // The return value/success is not checked because the function always fails
    // in debug builds, and if it somehow fails in release there is nothing to
    // do about it.
    ::HeapSetInformation( hLocalProcessHeap, HeapCompatibilityInformation, &useLowFragmentationHeapFlag, sizeof( useLowFragmentationHeapFlag ) );
    return hLocalProcessHeap;
}


BEGIN_EXTERN_C

#pragma warning( disable: 4074 )  // initializers put in compiler reserved initialization area
#pragma init_seg( compiler )

static HANDLE const hProcessHeap( getLowFragmentationHeap() );


__declspec(restrict, noalias) void * malloc( size_t const size )
{
    return ::HeapAlloc( hProcessHeap, 0, size );
}

__declspec(noalias) void free( void * const p )
{
    BOOL const success( ::HeapFree( hProcessHeap, 0, p ) );
    assert( success ); success;
}

__declspec(restrict, noalias) void * realloc( void * const p, size_t const size )
{
    return p ? ::HeapReAlloc( hProcessHeap, 0, p, size ) : ::HeapAlloc( hProcessHeap, 0, size );
}

__declspec(restrict, noalias) void *calloc( size_t const nitems, size_t const size )
{
    return ::HeapAlloc( hProcessHeap, HEAP_ZERO_MEMORY, nitems * size );
}

__declspec(restrict, noalias) void *_recalloc( void * const p, size_t const nitems, size_t const size )
{
    return p ? ::HeapReAlloc( hProcessHeap, HEAP_ZERO_MEMORY, p, nitems * size )
             : ::HeapAlloc  ( hProcessHeap, HEAP_ZERO_MEMORY,    nitems * size );
}

void *_calloc_crt(size_t const nitems, size_t const size )
{
    return calloc( nitems, size );
}

void *_nh_malloc( size_t const size, int /* nhFlag */ )
{
    return ::HeapAlloc( hProcessHeap, 0, size );
}

size_t _msize( void * const p )
{
    return ::HeapSize( hProcessHeap, 0, p );
}

END_EXTERN_C

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Software Developer Little Endian Ltd.
Croatia Croatia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions