Click here to Skip to main content
12,504,695 members (57,461 online)
Click here to Skip to main content

Stats

29.4K views
405 downloads
21 bookmarked
Posted

Multidevice ASIO output plugin for WinAMP

, 13 Feb 2009 CDDL
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)

Share

About the Author

Domagoj Šarić
Software Developer Little Endian Ltd.
Croatia Croatia
No Biography provided

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160919.1 | Last Updated 13 Feb 2009
Article Copyright 2009 by Domagoj Šarić
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid