⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hints

📁 早期freebsd实现
💻
📖 第 1 页 / 共 2 页
字号:
BABYL OPTIONS:Version: 5Labels:Note:   This is the header of an rmail file.Note:   If you are seeing it in rmail,Note:    it means the file has no messages in it.1,,Return-Path: <riedl@cs.purdue.edu>Received: from oswego.Oswego.EDU by g.oswego.edu (4.0/SMI-4.0)	id AA08377; Sun, 11 Feb 90 21:33:40 ESTReceived: by oswego.Oswego.EDU (5.57/Osw4.1.21)	id AA00896; Sun, 11 Feb 90 21:33:18 ESTReceived: from raid8.cs.purdue.edu by arthur.cs.purdue.edu (5.61/PURDUE_CS-1.2)	id <AA01233@arthur.cs.purdue.edu>; Sun, 11 Feb 90 21:30:14 -0500Received: from localhost by raid8.cs.purdue.edu (5.61/PURDUE_CS-1.2)	id <AA19140@raid8.cs.purdue.edu>; Sun, 11 Feb 90 21:30:08 -0500Message-Id: <9002120230.AA19140@raid8.cs.purdue.edu>To: dl@oswego.oswego.eduSubject: kudos for profiling and libg++In-Reply-To: Your message of Tue, 09 Jan 90 06:27:17 -0500.             <9001091127.AA09544@g.oswego.edu> Date: Sun, 11 Feb 90 21:30:04 ESTFrom: riedl@cs.purdue.edu*** EOOH ***Return-Path: <riedl@cs.purdue.edu>To: dl@oswego.oswego.eduSubject: kudos for profiling and libg++In-Reply-To: Your message of Tue, 09 Jan 90 06:27:17 -0500.             <9001091127.AA09544@g.oswego.edu> Date: Sun, 11 Feb 90 21:30:04 ESTFrom: riedl@cs.purdue.eduI was having some trouble with the performance of a concurrencycontroller I had written, and am very pleased to report that g++support for profiling, and the excellent libg++ data structure supportsaved the day!  I include a detailed description of the problem andsolution below, which you are welcome to send to any of the involvedparties for encouragement, or to publish for bragging rights (:-).Nice job!John------The basic problem was that two concurrency controllers that I hadwritten, called T/O and Lock for short, should have had similarperformance characteristics, but didn't.  After some days of work itbecame clear that T/O was significantly slower than Lock, for reasonsthat I couldn't understand.  I profiled the two routines and found theprofiles to be very similar, as expected, with the exception of alarge number of calls to compare_item in T/O:	calls to compare_item   	total timeT/O	118,112	   0.43		       10.76 secondsLOCK	6601*[2-3] 0.09 seconds		9.02 seconds(The numbers involved are small because I did the run for 100transactions.  Real runs will be for several orders of magnitude moretransactions.) (I don't have an exact number for the number of calls to compare itemfor Lock for obscure reasons, but my understanding of the programmakes me confident that it was called 2-3 times for each call to itsparent, which was called 6601 times.)The additional 1.74 seconds spent in T/O could almost all be accountedfor by calls to compare_item and its parent, SLSet::seek.  Since thedata structures involved were relatively small I expected that using afancier data structure wouldn't help, but I thought I should test thepotential.  I determined that the data structures involved would growto about 300 items, and that items would be accessed much more oftenthan they would be inserted.  So I timed versions using the linkedlist and using AVL trees:program		items	accesses	seconds (user time)sl-set		 300     10,000        	  7.70sl-set		 300     10,000        	  7.61sl-set		3000     10,000        	 91.35avl-set		 300      1,000 	  0.18avl-set		 300     10,000 	  0.68avl-set		 300	100,000		  6.15avl-set		3000     10,000		  1.48Clearly the AVL tree implementation was far superior, even for smallproblem sizes.  I installed the AVL sets in T/O and they solved theperformance problem I was having.  Profiling shows that before thechange:	calls to compare_item   	total timeT/O	118,112	   0.43		       10.76 secondsLOCK	6601*[2-3] 0.09 seconds		9.02 secondsAfter the change locking is the same, but:T/O	16,048     0.10 seconds		9.08 secondsThe lessons I take from this study are:1) Linked lists may cause performance problems even if the lists arerelatively short (< 100 items) if they are heavily used.2) The C++ library can be extremely advantageous.  In this case, Imade a two line change to my program to change to AVL trees.3) Profiling is essential to understanding program performance.John Riedl1,,Return-Path: <dl@g.oswego.edu>Received: from rocky.Oswego.EDU by g.oswego.edu (4.0/SMI-4.0)	id AA03598; Thu, 8 Feb 90 05:50:05 ESTReceived: by oswego.Oswego.EDU (5.57/Osw4.1.21)	id AA08592; Thu, 8 Feb 90 05:47:12 ESTReceived: from life.ai.mit.edu by nisc.nyser.net (5.61/2.1-NYSERNet NISC)	id AA07649; Thu, 8 Feb 90 05:44:40 -0500Received: from oswego.Oswego.EDU by life.ai.mit.edu (4.0/AI-4.10) id AA29896; Thu, 8 Feb 90 05:46:04 ESTReceived: by oswego.Oswego.EDU (5.57/Osw4.1.21)	id AA27161; Thu, 8 Feb 90 05:48:41 ESTReceived: by g.oswego.edu (4.0/SMI-4.0)	id AA03595; Thu, 8 Feb 90 05:48:50 ESTDate: Thu, 8 Feb 90 05:48:50 ESTFrom: dl@g.oswego.edu (Doug Lea)Message-Id: <9002081048.AA03595@g.oswego.edu>To: jose@csserver.cs.msstate.eduCc: bug-lib-g++@prep.ai.mit.eduIn-Reply-To: Jose Cordova's message of Wed, 7 Feb 90 17:28:57 CST <9002072328.AA07167@CSServer.CS.MsState.Edu>Subject: Run-time error when using 'get' with an istream objectReply-To: dl@oswego.oswego.edu*** EOOH ***Return-Path: <dl@g.oswego.edu>Date: Thu, 8 Feb 90 05:48:50 ESTFrom: dl@g.oswego.edu (Doug Lea)To: jose@csserver.cs.msstate.eduCc: bug-lib-g++@prep.ai.mit.eduIn-Reply-To: Jose Cordova's message of Wed, 7 Feb 90 17:28:57 CST <9002072328.AA07167@CSServer.CS.MsState.Edu>Subject: Run-time error when using 'get' with an istream objectReply-To: dl@oswego.oswego.edu> I am having trouble using the 'get' method for the 'istream' class.> It generates a 'Segmentation fault' error at run-time.  I know the> 'istream' is being opened correctly because reading into a 'String'> object with >> works fine.  Am I doing something wrong ?> The sample program and "data" illustrate the point:> > main()> {>     istream from("data",io_readonly,a_useonly);>     char *line;> >     from.get(line,15);>     cout << line;> }> > Sample "data" file contents:> word1 word2> word3> There are 3 istream functions for reading char*'s   istream&      get    (char* s, int n, char terminator = '\n');  istream&      getline(char* s, int n, char terminator = '\n');  istream&      gets   (char **s, char terminator = '\n'); The first two *require* an allocated char* (they differ onlyin how the trailing terminator is handled.) To use them, youmust supply either a char[N] or an allocated char*.The third automatically allocates space for you, that you shouldlater delete.For example,main(){    istream from("data",io_readonly,a_useonly);    char *line = new char[16]; // enough for string + null    char line2[16];    char* line3 = 0; // `= 0' so delete'able even if never allocated --                     // Not necessary in this example.    from.get(line,15);    from.get(line2,15);    from.gets(&line3,15);  // pass in the addr of line3    cout << line;    cout << line2;    cout << line3;    delete line;    delete line3;}Using the String class is a very good way to avoid dealing with thesekinds of char* allocation and semantics issues.-Doug1, answered,,Return-Path: <chowkwan@aerospace.aero.org>Received: from aerospace.aero.org ([130.221.192.10]) by g.oswego.edu (4.0/SMI-4.0)	id AA03846; Mon, 5 Feb 90 16:10:27 ESTReceived: from antares.aero.org by aerospace.aero.org with SMTP (5.61++/6.0.GT)	id AA24377 for dl@g.oswego.edu; Mon, 5 Feb 90 13:06:58 -0800Posted-Date: Mon, 5 Feb 90 13:06:50 PSTReceived: from merlin.aero.org by antares.aero.org (4.1/SMI-3.2-A4ant)	id AA20056 for dl@g.oswego.edu; Mon, 5 Feb 90 13:06:55 PSTMessage-Id: <9002052106.AA20056@antares.aero.org>Received: by merlin.aero.org (4.1/SMI-3.2-A4)	id AA03654 for dl@g.oswego.edu; Mon, 5 Feb 90 13:06:50 PSTDate: Mon, 5 Feb 90 13:06:50 PSTFrom: chowkwan@aerospace.aero.orgTo: dl@g.oswego.eduSubject: Checklist for using Map class*** EOOH ***Return-Path: <chowkwan@aerospace.aero.org>Posted-Date: Mon, 5 Feb 90 13:06:50 PSTDate: Mon, 5 Feb 90 13:06:50 PSTFrom: chowkwan@aerospace.aero.orgTo: dl@g.oswego.eduSubject: Checklist for using Map classI found your last message of Jan 20 was enough to get mestarted using the Map class.  I'm attaching some notesI made in LaTeX format which are intended to get newusers off and running quickly.  It's pretty much in theform of a checklist that they can just go down and follow.I was thinking it might be useful to you as a standardresponse to inquiries for help from neophytes like myself.               0  		cut here	    0----------------><--------------------------------><------------------               0                                    0\documentstyle{article}\title{Implementing Table Lookup Using the GNU Library}\begin{document}\section{Introduction}This note describes how to use the GNU class library Version 1.35.0to create lookup tables.  The advantage of using the GNU library is that the code to implement tables can be quickly generated.Hopefully, the code is also more reliable thanwhat we could write ourselves.In addition, the library provides four different lookupmechanisms. It is relatively easy to ``switch engines''and use the fastest one for our application.This note augments the ``User's Guide to GNU C++ Library''by filling in some gaps in the manual.Therefore, it is intended to complement, rather thanreplace the original manual.Section \ref{sec:general} describes the general procedurefor creating a lookup table.  Section \ref{sec:specific} gives a working example, in thiscase the creation of a lookup table for database objects.\section{Using the GNU Library to Create a Lookup Table}\label{sec:general}The GNU library provides four implementations of lookup tables:threaded AVL trees, splay trees, resizable hash tables, andchained hash tables.The hash table implementations provide double hashing.The class names for these implementations are shown belowin Table \ref{tab:imp}.All four classes are subclasses of the {\tt Map} class. \\Therefore, to create a lookup table, you must define a table class based on the abstract class {\tt Map} as well as one of the subclasses.The script {\tt genclass}, providedwith the GNU library, automates this process.\begin{table}[htb]\centering\caption{\label{tab:imp} GNU Implementations of Lookup Tables}\begin{tabular}{||l|l||} \hline{\bf Class Name} & {\bf Implementation Method} \\ \hline{\tt AVLMap} & Threaded AVL trees. \\{\tt SplayMap} & Splay trees. \\{\tt VHMap} & Resizable hash tables. \\{\tt CHMap} & Chained hash tables. \\ \hline\end{tabular} \\\end{table} A {\sl key} refers to the index for the tableand {\sl base value} refers to the basic datastored in the table that is returned upona keyed lookup.You need to define a hashing function and an equality function for the key.Finally, if you use pointers as your basevalue you need to typedef a name for the pointer.The steps you need to take are shown below.In these examples, {\tt $<$K$>$} is the nameof the key class, {\tt $<$B$>$} the name of the class for the base value,{\tt $<$BP$>$} the name of the type pointer to base value,and {\tt $<$M$>$} the name of one of the four {\tt Map} subclasses. \\\begin{tabular}{||r|l|l||} \hline&&  {\bf Name of } \\{\bf Step} & {\bf Action} & {\bf Affected File} \\  \hline1 & Create functions {\tt $<$K$>$HASH} & {\tt $<$K$>$.defs.h} \\  & and {\tt $<$K$>$EQ}. &{\tt $<$K$>$.defs.cc }  \\ \hline2 & Define {\tt DEFAULT\_INITIAL\_CAPACITY} & {\tt $<$K$>$.defs.h} \\ \hline3 & Create typedef {\tt $<$BP$>$}. & {\tt  $<$B$>$.h}  \\  & for  pointer to base class. & \\ \hline4 & Create abstract class with  & {\tt $<$K$>$.$<$BP$>$.Map.h}  \\  & {\tt genclass -2 $<$K$>$ ref $<$BP$>$ val Map}&   {\tt $<$K$>$.$<$BP$>$.Map.cc} \\ \hline5 & Edit {\tt $<$K$>$.$<$BP$>$.Map.h} to include &{\tt $<$K$>$.$<$BP$>$.Map.h} \\  & {\tt $<$K$>$.defs.h} and {\tt  $<$B$>$.h}. &   \\ \hline6 & Create table class for specific & {\tt $<$K$>$.$<$BP$>$.$<$M$>$.h} \\  & lookup implementation method with & {\tt $<$K$>$.$<$BP$>$.$<$M$>$.cc} \\   & {\tt genclass -2 $<$K$>$ ref $<$BP$>$ val $<$M$>$ } & \\ \hline\end{tabular} \\The {\tt $<$K$>$} and {\tt $<$BP$>$} arguments to {\tt genclass}can be qualified by either {\tt val} or {\tt ref} depending onwhether the reference is by value or by reference.\section{Example: Table Lookup Class for Database Objects}\label{sec:specific}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -