Welcome, Guest. Please login or register.

Author Topic: Counting on AllocVec's size memo..  (Read 13662 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Counting on AllocVec's size memo..
« Reply #44 from previous page: January 09, 2007, 09:02:13 PM »
MAllocVec will write zeropage if AllocMem fails, fixed version:
Code: [Select]
APTR MAllocVec( unsigned long byteSize, unsigned long requirements )
{
    if (SysBase->LibNode.lib_Version >= 36)
    {
        return AllocVec(byteSize, requirements);
    }
    else
    {
        unsigned long *data;

        byteSize += sizeof(unsigned long);
        data = (unsigned long *)AllocMem(byteSize, requirements);
        if (data)
        {
            *data = byteSize;
            data++;
        }
        return data;
    }
}


Small fix to MFreeVec aswell, in case this routine is to be used as drop-in replacement for FreeVec:
Code: [Select]

void MFreeVec( APTR memoryBlock )
{
    if (SysBase->LibNode.lib_Version >= 36)
    {
        FreeVec(memoryBlock);
    }
    else if (MemoryBlock)
    {
        unsigned long byteSize;
        unsigned long *data;

        data = (unsigned long*)memoryBlock;
        data--;
        byteSize = *data;
        FreeMem(data, byteSize);
    }
}


Excuse me, I just can't help myself. ;-)
 

Offline koaftder

  • Hero Member
  • *****
  • Join Date: Apr 2004
  • Posts: 2116
    • Show only replies by koaftder
    • http://koft.net
Re: Counting on AllocVec's size memo..
« Reply #45 on: January 09, 2007, 10:32:02 PM »
I still can't get used to that leading '{' on its own line. Am I defective? Why do people do this?
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Counting on AllocVec's size memo..
« Reply #46 on: January 09, 2007, 10:47:02 PM »
Wikipedia: Indent Style#BSD/Allman style

Basically it's easier to read: More "spacious" and it's easier to see where blocks start and end (just find  visually matching brackets).

This is not the universally superior indent style, but it is fairly common. However, the most important thing is to stay consistent: When you choose a style, stick to it. Don't change styles (at least not within the same project).

See more at Wikipedia: Programming style
 

Offline koaftder

  • Hero Member
  • *****
  • Join Date: Apr 2004
  • Posts: 2116
    • Show only replies by koaftder
    • http://koft.net
Re: Counting on AllocVec's size memo..
« Reply #47 on: January 09, 2007, 11:09:34 PM »
Quote

Piru wrote:
Wikipedia: Indent Style#BSD/Allman style

Basically it's easier to read: More "spacious" and it's easier to see where blocks start and end (just find  visually matching brackets).

This is not the universally superior indent style, but it is fairly common. However, the most important thing is to stay consistent: When you choose a style, stick to it. Don't change styles (at least not within the same project).

See more at Wikipedia: Programming style


I guess I'm in the "BSD/KNF" camp. I guess I need to get used to the Allman style. Allman isn't easier to read to me.... I'm doing a lot of windows stuff right now and its all some perverted allman style. Driving me nuts. Especially allan style with win32 calls with 1000 parameters blocked up on multiple lines.
 

Offline CannonFodder

  • Hero Member
  • *****
  • Join Date: Sep 2003
  • Posts: 1115
    • Show only replies by CannonFodder
Re: Counting on AllocVec's size memo..
« Reply #48 on: January 09, 2007, 11:10:58 PM »
Quote

koaftder wrote:
I still can't get used to that leading '{' on its own line. Am I defective? Why do people do this?


Hallelujah I am not alone in this world!

I cannot stand that.  It's ridiculous.

BSD/KNF style

Much better.
People are hostile to what they do not understand - Imam Ali ibn Abi Talib(AS)
 

Offline koaftder

  • Hero Member
  • *****
  • Join Date: Apr 2004
  • Posts: 2116
    • Show only replies by koaftder
    • http://koft.net
Re: Counting on AllocVec's size memo..
« Reply #49 on: January 09, 2007, 11:18:03 PM »
Quote

CannonFodder wrote:

Hallelujah I am not alone in this world!

Much better.


you definately are not alone. I hate the single line entry '{' what a waste of space. The indent make it obvious what scope one is in. The trailing '}' is ok, it denotes down scope. Thats all you need.
 

Offline CannonFodder

  • Hero Member
  • *****
  • Join Date: Sep 2003
  • Posts: 1115
    • Show only replies by CannonFodder
Re: Counting on AllocVec's size memo..
« Reply #50 on: January 09, 2007, 11:18:46 PM »
Code: [Select]

void MFreeVec( APTR memoryBlock ) {
    if (SysBase->LibNode.lib_Version >= 36) {
        FreeVec(memoryBlock);
    }

    else if (MemoryBlock) {
        unsigned long byteSize;
        unsigned long *data;

        data = (unsigned long*)memoryBlock;
        data--;
        byteSize = *data;
        FreeMem(data, byteSize);
    }
}


Much nicer. ;-)
People are hostile to what they do not understand - Imam Ali ibn Abi Talib(AS)
 

Offline koaftder

  • Hero Member
  • *****
  • Join Date: Apr 2004
  • Posts: 2116
    • Show only replies by koaftder
    • http://koft.net
Re: Counting on AllocVec's size memo..
« Reply #51 on: January 09, 2007, 11:19:49 PM »
Quote

CannonFodder wrote:
Code: [Select]

void MFreeVec( APTR memoryBlock ) {
    if (SysBase->LibNode.lib_Version >= 36) {
        FreeVec(memoryBlock);
    }

    else if (MemoryBlock) {
        unsigned long byteSize;
        unsigned long *data;

        data = (unsigned long*)memoryBlock;
        data--;
        byteSize = *data;
        FreeMem(data, byteSize);
    }
}


Much nicer. ;-)


wow, I can actually read that.
 

Offline koaftder

  • Hero Member
  • *****
  • Join Date: Apr 2004
  • Posts: 2116
    • Show only replies by koaftder
    • http://koft.net
Re: Counting on AllocVec's size memo..
« Reply #52 on: January 09, 2007, 11:21:27 PM »
Quote

CannonFodder wrote:
Code: [Select]

void MFreeVec( APTR memoryBlock ) {
    if (SysBase->LibNode.lib_Version >= 36)
        FreeVec(memoryBlock);
    else if (MemoryBlock) {
        unsigned long byteSize;
        unsigned long *data;

        data = (unsigned long*)memoryBlock;
        data--;
        byteSize = *data;
        FreeMem(data, byteSize);
    }
}



sorry, had to do that.
 

Offline CannonFodder

  • Hero Member
  • *****
  • Join Date: Sep 2003
  • Posts: 1115
    • Show only replies by CannonFodder
Re: Counting on AllocVec's size memo..
« Reply #53 on: January 09, 2007, 11:43:54 PM »
Quote

koaftder wrote:
Quote

CannonFodder wrote:
Code: [Select]

void MFreeVec( APTR memoryBlock ) {
    if (SysBase->LibNode.lib_Version >= 36)
        FreeVec(memoryBlock);
    else if (MemoryBlock) {
        unsigned long byteSize;
        unsigned long *data;

        data = (unsigned long*)memoryBlock;
        data--;
        byteSize = *data;
        FreeMem(data, byteSize);
    }
}



sorry, had to do that.


:lol:
People are hostile to what they do not understand - Imam Ali ibn Abi Talib(AS)
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Counting on AllocVec's size memo..
« Reply #54 on: January 09, 2007, 11:52:28 PM »
Oh no, yet another holy war... But of course it's a matter of taste....






Except that BSD/Allman is teh bestest!!!1






:-D
 

Offline koaftder

  • Hero Member
  • *****
  • Join Date: Apr 2004
  • Posts: 2116
    • Show only replies by koaftder
    • http://koft.net
Re: Counting on AllocVec's size memo..
« Reply #55 on: January 10, 2007, 12:14:40 AM »
Quote

Piru wrote:
Oh no, yet another holy war... But of course it's a matter of taste....
Except that BSD/Allman is teh bestest!!!1
:-D


Might as well be, everybody is doing it. I'll have to learn to cope.
 

Offline CannonFodder

  • Hero Member
  • *****
  • Join Date: Sep 2003
  • Posts: 1115
    • Show only replies by CannonFodder
Re: Counting on AllocVec's size memo..
« Reply #56 on: January 10, 2007, 01:02:21 AM »
Quote

Piru wrote:
Oh no, yet another holy war... But of course it's a matter of taste....


Except that BSD/Allman is teh bestest!!!1

:-D


Infidel!!! ;-)
People are hostile to what they do not understand - Imam Ali ibn Abi Talib(AS)