Re: installing Euphoria 4 on old machine (windows 98SE)

new topic     » goto parent     » topic index » view thread      » older message » newer message
SDPringle said...

Let's get something straight first. All OSes we maintain have aligned 4 memory. ALIGN4 is a misnomer. The flag should have been ALIGN8 and when defined the system should assume all memory returned from malloc() is 8-byte aligned.

I thought 'ALIGN4' meant that the OS returned malloc'ed RAM on a 4-byte boundary, and thus the term in not a misnomer.

SDPringle said...

The cost is, a bitwise and operation, and two conditionals on each non-cached memory allocation operation. The managed memory doesn't need to check for alignment. If your machine can run NT or higher it is not something to worry about.

Your quoting of the code involved is a little bit incorrect, IMO. To me the ALIGN4 code (excluding the 'free-ing' and 'realloc-ing' code elsewhere) is effectively ...

nbytes += align4; // allow for possible 4-aligned addresses 
do { 
    p = malloc(nbytes+8); 
    alignment = ((unsigned long)p) & 7; 
    if (alignment == 0) { 
        // address just happens to be 8-aligned this time. 
        if (align4 && *(int *)(p-4) == MAGIC_FILLER) 
            // don't free. grab a new one. 
            continue;  // magic is there by chance! 
        // (this case is remotely possible on Win95 only) 
        return p;   // already 8-aligned, should happen most of the time 
    } 
    if (alignment != 4) { 
        RTFatal("malloc block NOT 4-byte aligned!\n"); 
    } 
    if (align4) { 
        *(int *)p = MAGIC_FILLER; 
        assert((((unsigned int)p + 4) & 7) == 0); 
        return p+4; 
    } 
    /* first occurrence of a 4-aligned block */ 
    free(p); 
    align4 = 4;  // start handling 4-aligned blocks 
    nbytes += align4; 
} while (TRUE); 

and when ALIGN4 is not defined the code is effectively ...

assert(((unsigned int)p & 7) == 0); 
return p; 

And as for 'managed-mem' not needing to check for alignment, well that's not quite right really either. All 'managed-mem' means is that before doing a malloc() call, first see if we don't already have a block of (aligned-8) memory available to use, but if we don't have one available, we then need to do an alignment check on the malloc() we use.

But in any case, I'm glad to see that the overhead on modern machines is negligible.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu