The Artima Developer Community
Sponsored Link

Agile Buzz Forum
BAd APIs

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Keith Ray

Posts: 658
Nickname: keithray
Registered: May, 2003

Keith Ray is multi-platform software developer and Team Leader
BAd APIs Posted: Jul 26, 2004 2:02 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by Keith Ray.
Original Post: BAd APIs
Feed Title: MemoRanda
Feed URL: http://homepage.mac.com/1/homepage404ErrorPage.html
Feed Description: Keith Ray's notes to be remembered on agile software development, project management, oo programming, and other topics.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Keith Ray
Latest Posts From MemoRanda

Advertisement

Bad APIs start at the very beginning. For example, the C function alloc(size_t size) - a function to allocate memory in the heap - creates a block of memory; but what does it return? Not a data-structure describing the block, but half of that information, just the pointer. Imagine what could have happened if that function has been defined correctly:

struct MemoryBlock
{
    char*  block_start;
    size_t block_size;
};

MemoryBlock Alloc( size_t sizeIn );

void Free( MemoryBlock * blockIn );

If these two pieces -- pointer and length -- were always kept together, then other data-types implemented in C, like strings could have been safer...


void StringCopy( MemoryBlock* destString, MemoryBlock* sourceString );

Read: BAd APIs

Topic: Whoa - I'm thinking twice Previous Topic   Next Topic Topic: Re: JIS on Commodities

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use