News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

MSVCRT aligned malloc

Started by MichaelW, July 28, 2012, 05:46:26 PM

Previous topic - Next topic

jj2007

Quote from: nidud on May 01, 2013, 06:04:02 AM
> They don't.
They do, that is, functions that improves speed (mostly string/mem functions) with aligned pointers do.

We are talking gsl_ functions here. They don't - I've checked.

QuoteI haven't tested the gsl_matrix_alloc function, but it should be rather easy to manipulate (align) the data pointer to 16-byte if needed.

If you think it's "rather easy" to compile a Linux-based major software package on Windows, please don't be shy, just do it. Unless, of course, you have better things to do than chasing missing or incompatible header files for the rest of the night. I know some activities that are a lot funnier.

hutch--

There is something here that confuses me and this is after I have bothered to read this thread in detail, if you can bypass external library's dependence on specific memory allocation strategies then why bother to use a complicated mess like VCs aligned memory ? Without delving into the guts of a range of C libraries, usually a mess of this type is so it fits a range of data types that are specific to the C compiler.

If you don't have to suffer the C compiler, why the hell would you bother with a mess like this ? The mechanism in assembler is very easy to deal with, use "Anythingyoulike"Alloc to allocate a block of memory, tweak the size upwards by at least the alignment amount, align the front of the block to the alignment you require and pass back the aligned address. About all you have to do is keep track of the original pointer and make sure you deallocate the correct address.

Gunther

Quote from: hutch-- on May 01, 2013, 06:51:12 AM
The mechanism in assembler is very easy to deal with, use "Anythingyoulike"Alloc to allocate a block of memory, tweak the size upwards by at least the alignment amount, align the front of the block to the alignment you require and pass back the aligned address. About all you have to do is keep track of the original pointer and make sure you deallocate the correct address.

That's exactly what I would do.

Gunther
You have to know the facts before you can distort them.

qWord

Quote from: jj2007 on May 01, 2013, 06:47:46 AM
If you think it's "rather easy" to compile a Linux-based major software package on Windows, please don't be shy, just do it. Unless, of course, you have better things to do than chasing missing or incompatible header files for the rest of the night. I know some activities that are a lot funnier.
not funny but time consuming - you need MinGW+MSYS. For building, read the INSTALL file in the gsl dir or follow this instructions.
MREAL macros - when you need floating point arithmetic while assembling!

Gunther

Hi qWord,

Quote from: qWord on May 01, 2013, 07:11:31 AM
not funny but time consuming - you need MinGW+MSYS. For building, read the INSTALL file in the gsl dir or follow this instructions.

you're right, that's a bedlam.

Gunther
You have to know the facts before you can distort them.

nidud

#35
deleted

dedndave

i think the problem is that gsl_matrix_alloc allocates by multiplying a row and column count
so - you can't easily add a few extra bytes and align
you would have to add a row or a column
then, you have to adjust your reference to the matrix, which makes for cluttered looking code, i suppose

personally, i would ask HeapAlloc for N+15 bytes and align it   :P
if the matrix is created and freed inside a single proc, use the stack as i mentioned earlier

jj2007

Quote from: dedndave on May 01, 2013, 08:54:59 AM
i think the problem is that gsl_matrix_alloc allocates by multiplying a row and column count
so - you can't easily add a few extra bytes and align

Spot on, Dave :t
And thanks anyway for all the good advice :icon14:

MichaelW

In my quick search it looks like all of the matrix functions reference the array with a pointer. If this is the case, and there is not some hidden functionality to trip this approach up, you could copy the array to a properly aligned buffer, modify the pointer, and free the old array.
Well Microsoft, here's another nice mess you've gotten us into.