OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   C++ SAX Question

[ Lists Home | Date Index | Thread Index ]
  • From: RJA@dip.co.uk
  • To: xml-dev@ic.ac.uk
  • Date: Wed, 21 Oct 1998 14:14:58 +0100





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@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo@ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS