[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

C++ SAX Question

  • From: RJA@d...
  • To: xml-dev@i...
  • Date: Wed, 21 Oct 1998 14:14:58 +0100

c sax example




Richard J. Anderson@DI
10/21/98 02:14 PM

Hi,

I'm currently working on some C++ SAX definitions has was wondering if I
should be using references for strings or not.    Take the following
snippet from the definitions:

class CSAXDocumentHandler
{
public:
    virtual void startDocument() = 0;
    virtual void endDocument() = 0;
    virtual void startElement( string sName,
                      CSAXAttributeList& Attributes ) = 0;
    virtual void endElement( string sName ) = 0;
    virtual void processingInstruction( string sTarget, string sData ) = 0;
    virtual void characters( char ch[],
                    int start,
                    int length) = 0;
    virtual void setDocumentLocator( CSAXLocator &locator ) = 0;
    virtual void ignorableWhitespace( char ch[],
                          int start,
                          int length) = 0;

//+------------------------------------------------------------------------
    //+ additonal methods not supported by SAX

//+------------------------------------------------------------------------
    virtual void comment( string Comment ) = 0;
    };

Each method that accepts a string parameter is defined to accept it by
value ( eg 'string' )  rather than by reference, ( eg 'string&' ).   Is
this a good or bad idea ?

So far I can think of the following reasons why a reference would be
better:
1. No additional/allocation is required for each element callback.
2.  Passing by value can cause memory allocation issues.  For example, in a
dll, the string would be constructed by the caller of the function on their
heap  (eg.  the  parser),  but  deleted  by  the implemetor of the document
handler  class  whose  heap would probably raise an exception.  ( I'm still
pretty  new  to STL so maybe you can change the allocation mechanism or I'm
completly mistaken :-) ).

I  would  be  interested  in hearing some feedback on this subject, as I an
hoping to publish my C++ SAX definitions in the next week or so.

Kind Regards,

Richard Anderson.


***  This post is of a personal nature and does not in anyway represent the
opinions or developments of data interchange plc



xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i...
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo@i... the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@i... the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@i...)


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.