diff -Nur mecab-0.81.orig/Wakati mecab-0.81/Wakati
--- mecab-0.81.orig/Wakati	1970-01-01 09:00:00.000000000 +0900
+++ mecab-0.81/Wakati	2005-04-22 16:46:26.000000000 +0900
@@ -0,0 +1,7 @@
+�	̤�θ�,*,*,*,*,*,*,*,*
+��	̤�θ�,*,*,*,*,*,*,*,*
+��	̤�θ�,*,*,*,*,*,*,*,*
+�	̤�θ�,*,*,*,*,*,*,*,*
+��	̤�θ�,*,*,*,*,*,*,*,*
+��	̤�θ�,*,*,*,*,*,*,*,*
+EOS
diff -Nur mecab-0.81.orig/doc/libmecab.html mecab-0.81/doc/libmecab.html
--- mecab-0.81.orig/doc/libmecab.html	2004-06-21 18:34:35.000000000 +0900
+++ mecab-0.81/doc/libmecab.html	2005-04-19 19:27:23.000000000 +0900
@@ -46,6 +46,29 @@
 $B$3$N%]%$%s%?$rDL$7$F2r@O$r9T$$$^$9(B.<br>
 </dd>
 
+<dt><code><font color="#dc143c">int</font><font color=
+"DarkBlue">mecab_load_dictionary</font> (int, char**)</code></dt>
+
+<dd>$BJ#?t$N(Bmecab$B%$%s%9%?%s%94V$G6&M-2DG=$J<-=q$*$h$SJ8;z<o%F!<%V%k$r=i4|2=$7$^$9(B.<br>
+$B0z?t$O(B, mecab_new $B$HF1$8J}K!$G=hM}$5$l$^$9(B.<br>
+$B6&M-2DG=$J<-=q$O(B1$B%W%m%;%9$K$D$-(B1$B$D$N$_$G$9(B.
+$BK\4X?t$G3NJ]$5$l$?<-=q$*$h$SJ8;z<o%F!<%V%k$O(B,
+(prefix $B$d(B charset $B$N>r7o$,F10l$G$"$l$P(B)$B0J9_=i4|2=$5$l$?(B mecab $B%$%s%9%?%s%94V$G(B,
+$B<+F0E*$K6&M-$5$l$^$9(B.
+<br>
+</dd>
+
+<dt><code><font color="#dc143c">mecab_t *</font><font color=
+"DarkBlue">mecab_new3</font> (void)</code></dt>
+
+<dd>mecab $B$N%$%s%9%?%s%9$r@8@.$7$^$9(B.<br>
+$B;vA0$K(B mecab_load_dictionary $B$r<B9T$9$kI,MW$,$"$j$^$9(B.
+mecab_load_dictionary $B<B9T;~$HF10l$N0z?t$,;XDj$5$l$?$b$N$H$_$J$7(B,
+$B<-=q$HJ8;z<o%F!<%V%k$r6&M-$9$k(B mecab $B%$%s%9%?%s%9$r@8@.$7$^$9(B.<br>
+$B@.8y$9$l$P(B, mecab_t $B7?$N%]%$%s%?$,JV$C$F$-$^$9(B.
+$B$3$N%]%$%s%?$rDL$7$F2r@O$r9T$$$^$9(B.<br>
+</dd>
+
 <dt><code><font color="#dc143c">char *</font><font color=
 "DarkBlue">mecab_strerror</font> (mecab_t* m)</code></dt>
 
@@ -357,6 +380,10 @@
 $B3d$j$"$F$i$l$k$?$a(B, $BJ#?t$N%$%s%9%?%s%9$r:n@.$7$F$b(B,
 $BB?$/$N%a%b%j$r;HMQ$9$k$3$H$O(B $B$"$j$^$;$s(B.</p>
 
+<p>$BJ#?t$N%$%s%9%?%s%9$GF10l$N<-=q$r;HMQ$9$k>l9g$O(B,
+$B%$%s%9%?%s%9@8@.A0$K(B mecab_load_dictionary $B$r<B9T$9$l$P(B,
+$BF10lO@M}%"%I%l%9$N<-=q$,6&M-$5$l(B,$BB?$/$NO@M}%a%b%j6u4V$r;HMQ$9$k$3$H$,$"$j$^$;$s(B.</p>
+
 <h3>1$B%$%s%9%?%s%9$rJ#?t$N%9%l%C%I$+$i%"%/%;%9$9$k>l9g(B</h3>
 
 <p>$B$3$N>l9g$O(B, $BF14|$r$H$kI,MW$,$"$j$^$9(B.
diff -Nur mecab-0.81.orig/src/connector.h mecab-0.81/src/connector.h
--- mecab-0.81.orig/src/connector.h	2004-08-07 03:05:14.000000000 +0900
+++ mecab-0.81/src/connector.h	2005-04-19 19:27:23.000000000 +0900
@@ -38,6 +38,7 @@
     unsigned int size2;
     unsigned int size3;
     std::string _what;
+    bool shared;
 
   public:
     void clear () { /* do nothing */ };
@@ -52,7 +53,19 @@
     bool open (Param &param)
     {
        try {
-	  std::string fileName = createFileName (param.getProfileString ("dicdir"), CONNECTION_FILE);
+	  std::string prefix = param.getProfileString ("dicdir");
+	  SharedResource *sharedResource = lookupSharedResource(prefix.c_str());
+	  if (sharedResource) {
+	    mmmap = sharedResource->mmmap;
+	    mmmap.no_unmap();
+	    size1 = sharedResource->size1;
+	    size2 = sharedResource->size2;
+	    size3 = sharedResource->size3;
+	    matrix = sharedResource->matrix;
+	    shared = true;
+	    return true;
+	  }
+	  std::string fileName = createFileName (prefix, CONNECTION_FILE);
 
 	  if (! mmmap.open (fileName.c_str()))
 	    throw std::runtime_error (mmmap.what ());
@@ -62,6 +75,7 @@
 	    throw std::runtime_error ("file size is invalid");
 	  
 	  matrix = mmmap.begin () + 3;
+	  shared = false;
 	  return true;
        }
 
@@ -74,6 +88,7 @@
      
     bool close ()
     {
+      if (shared) { return true; }
        return mmmap.close();
     }
 
diff -Nur mecab-0.81.orig/src/dictionary.h mecab-0.81/src/dictionary.h
--- mecab-0.81.orig/src/dictionary.h	2005-03-20 22:18:57.000000000 +0900
+++ mecab-0.81/src/dictionary.h	2005-04-19 19:27:23.000000000 +0900
@@ -28,8 +28,39 @@
 #include "mmap.h"
 #include "common.h"
 
+#include "param.h"
+
 namespace MeCab {
    
+  class SharedResource
+  {
+  public:
+    class CharTable {
+    public:
+      unsigned char ascii_table [256];
+      unsigned char ja_table    [256][256];
+      int charset;
+    };
+    bool opened;
+    Param param;
+    char dicdir[PATH_MAX];
+    Mmap<Token> tmmap;
+    Mmap<char>  immap;
+    Mmap<char>  dmmap;
+    Mmap <unsigned short> mmmap;
+    unsigned short *matrix;
+    unsigned int size1;
+    unsigned int size2;
+    unsigned int size3;
+    CharTable *ct;
+    bool open (int, char**);
+    bool close ();
+
+    SharedResource();
+    ~SharedResource();
+  };
+  SharedResource *lookupSharedResource(const char *prefix);
+  SharedResource *lookupSharedResource(int charset);
   // Language Independent Dictionary 
   class Dictionary 
   {
@@ -41,10 +72,23 @@
     Token *result   [512];
     Darts::DoubleArray::result_type daresult [256];
     std::string _what;
+    bool shared;
 
   public:
     bool open (const char *prefix)
     {
+      SharedResource *sharedResource = lookupSharedResource(prefix);
+      if (sharedResource) {
+	dmmap = sharedResource->dmmap;
+	dmmap.no_unmap();
+	da.setArray ((void *)dmmap.begin());
+	tmmap = sharedResource->tmmap;
+	tmmap.no_unmap();
+	immap = sharedResource->immap;
+	immap.no_unmap();
+	shared = true;
+	return true;
+      }
       try {
 	std::string dmapfileName = createFileName (std::string (prefix), DOUBLE_ARRAY_FILE);
 	if (! dmmap.open (dmapfileName.c_str())) throw std::runtime_error (dmmap.what());
@@ -56,6 +100,7 @@
 	std::string imapfileName = createFileName (std::string (prefix), POS_FILE);
 	if (! immap.open (imapfileName.c_str())) throw std::runtime_error (immap.what());
 
+	shared = false;
 	return true;
       }
 
@@ -68,6 +113,7 @@
 
     bool close () 
     {
+       if (shared) { return true; }
        dmmap.close();
        tmmap.close();
        immap.close();
diff -Nur mecab-0.81.orig/src/japanese_tokenizer.cpp mecab-0.81/src/japanese_tokenizer.cpp
--- mecab-0.81.orig/src/japanese_tokenizer.cpp	2004-06-21 18:34:35.000000000 +0900
+++ mecab-0.81/src/japanese_tokenizer.cpp	2005-04-19 19:27:23.000000000 +0900
@@ -42,6 +42,16 @@
       throw std::runtime_error (_what);
     }
 
+    SharedResource *sr = lookupSharedResource(charset);
+    if (sr) {
+      t = sr->ct;
+      shared = true;
+      return true;
+    }
+    
+    t = new SharedResource::CharTable;
+    t->charset = charset;
+    shared = false;
     // Ref: Understanding ���ܸ������� Page 298- 
     // JISX 2080-1990 Kuten code table
     unsigned char kuten_table [95][95];
@@ -67,23 +77,23 @@
     kuten_table[1][28] = KATAKANA; // ��
 
     // ascii table
-    for (int i = 0;   i <= 255;  ++i) ascii_table[i] = OTHER;
-    for (int i = 33;  i <= 47;   ++i) ascii_table[i] = SYMBOL;
-    for (int i = 48;  i <= 57;   ++i) ascii_table[i] = ALPHANUMERIC;
-    for (int i = 58;  i <= 64;   ++i) ascii_table[i] = SYMBOL;
-    for (int i = 65;  i <= 90;   ++i) ascii_table[i] = ALPHA;
-    for (int i = 91;  i <= 96;   ++i) ascii_table[i] = SYMBOL;
-    for (int i = 97;  i <= 122;  ++i) ascii_table[i] = ALPHA;
-    for (int i = 123; i <= 126;  ++i) ascii_table[i] = SYMBOL; 
-
-    ascii_table[32] = SPACE; // ' '
-    ascii_table[13] = SPACE; // '\r'
-    ascii_table[10] = SPACE; // '\n'
-    ascii_table[9]  = SPACE; // '\t'
+    for (int i = 0;   i <= 255;  ++i) t->ascii_table[i] = OTHER;
+    for (int i = 33;  i <= 47;   ++i) t->ascii_table[i] = SYMBOL;
+    for (int i = 48;  i <= 57;   ++i) t->ascii_table[i] = ALPHANUMERIC;
+    for (int i = 58;  i <= 64;   ++i) t->ascii_table[i] = SYMBOL;
+    for (int i = 65;  i <= 90;   ++i) t->ascii_table[i] = ALPHA;
+    for (int i = 91;  i <= 96;   ++i) t->ascii_table[i] = SYMBOL;
+    for (int i = 97;  i <= 122;  ++i) t->ascii_table[i] = ALPHA;
+    for (int i = 123; i <= 126;  ++i) t->ascii_table[i] = SYMBOL; 
+
+    t->ascii_table[32] = SPACE; // ' '
+    t->ascii_table[13] = SPACE; // '\r'
+    t->ascii_table[10] = SPACE; // '\n'
+    t->ascii_table[9]  = SPACE; // '\t'
 
     for (int i = 0; i < 255; ++i)
       for (int j = 0; j < 255; ++j)
-	ja_table[i][j] = OTHER;
+	t->ja_table[i][j] = OTHER;
 
     // for all kuten tabele 
     for (unsigned int i = 1; i <= 94 ; ++i) {
@@ -96,17 +106,17 @@
 	case UTF8:      kuten2jis  (h,l); break; // use UTF8 -> JISX0208 table
 	default:        kuten2euc  (h,l); break; // never be here
 	}
-	ja_table[h][l] = kuten_table[i][j];
+	t->ja_table[h][l] = kuten_table[i][j];
       }
     }
 
     // EUC-hankaku-kana
     if (charset == EUC_JP) 
-      for (int i = 166; i <= 222;  ++i) ja_table[142][i] = HALFKATAKANA;
+      for (int i = 166; i <= 222;  ++i) t->ja_table[142][i] = HALFKATAKANA;
     else if (charset == SHIFT_JIS)
-      for (int i = 166; i <= 222;  ++i) ascii_table[i] = HALFKATAKANA;      
+      for (int i = 166; i <= 222;  ++i) t->ascii_table[i] = HALFKATAKANA;      
 
-    return Tokenizer::open (param);
+    return true;
   }
    
   Node *JapaneseTokenizer::lookup (const char *begin, const char *end)
@@ -155,4 +165,16 @@
     newNode->rnext   = resultNode;
     return newNode;
   }
+  SharedResource::CharTable *JapaneseTokenizer::shareCharTable()
+  {
+    shared = true;
+    return t;
+  }
+  bool JapaneseTokenizer::close () 
+  {
+    if (!shared) {
+      delete t; t = 0;
+    }
+    return Tokenizer::close ();
+  }
 };
diff -Nur mecab-0.81.orig/src/japanese_tokenizer.h mecab-0.81/src/japanese_tokenizer.h
--- mecab-0.81.orig/src/japanese_tokenizer.h	2004-03-08 16:40:52.000000000 +0900
+++ mecab-0.81/src/japanese_tokenizer.h	2005-04-19 19:27:23.000000000 +0900
@@ -48,12 +48,16 @@
 
     enum { EUC_JP, SHIFT_JIS, UTF8 };
 
+    /*
     unsigned char ascii_table [256];
     unsigned char ja_table    [256][256];
+    */
     int charset;
+    SharedResource::CharTable *t;
+    bool shared;
 
   public:
-     JapaneseTokenizer (Param &param): charset(EUC_JP) 
+    JapaneseTokenizer (Param &param): charset(EUC_JP), t(0)
                  { if (! this->open (param)) throw std::runtime_error (_what); }
     ~JapaneseTokenizer() { this->close (); };
 
@@ -61,7 +65,9 @@
     void postprocess (const char *, const char *) { /* Do nothing */ };
 
     bool open (Param &); 
+    bool close ();
     Node *lookup (const char *, const char *);
+    SharedResource::CharTable *shareCharTable();
 
     inline int getCharClass (const char *str, const char *end, unsigned int &next) const
     {
@@ -70,10 +76,10 @@
       case EUC_JP:
 	if (str[0] & 0x80) {
 	  next = 2;
-	  return ja_table[static_cast<unsigned char>(str[0])][static_cast<unsigned char>(str[1])];
+	  return t->ja_table[static_cast<unsigned char>(str[0])][static_cast<unsigned char>(str[1])];
 	}
 	next = 1;
-	return ascii_table[static_cast<unsigned char>(str[0])];
+	return t->ascii_table[static_cast<unsigned char>(str[0])];
 	break;
 
       case SHIFT_JIS: 
@@ -83,10 +89,10 @@
 	      (static_cast<unsigned char>(str[0]) >= 0xa0 &&
 	       static_cast<unsigned char>(str[0]) <= 0xdf)) {
 	    next = 1;
-	    return ascii_table[static_cast<unsigned char>(str[0])];
+	    return t->ascii_table[static_cast<unsigned char>(str[0])];
 	  } else if (len >= 2 && (str[0] & 0x80)) {
 	    next = 2;
-	    return ja_table[static_cast<unsigned char>(str[0])][static_cast<unsigned char>(str[1])];
+	    return t->ja_table[static_cast<unsigned char>(str[0])][static_cast<unsigned char>(str[1])];
 	  } else { // unkwon
 	    next = 1;
 	    return OTHER;
@@ -101,7 +107,7 @@
 
 	  if (static_cast<unsigned char>(str[0]) < 0x80) {  // 1byte
 	    next = 1;
-	    return ascii_table[static_cast<unsigned char>(str[0])]; // this is same as ascii
+	    return t->ascii_table[static_cast<unsigned char>(str[0])]; // this is same as ascii
 	  } else if (len >= 2 && static_cast<unsigned char>(str[0]) < 0xE0) { // 2 bytes 
 	    ucs2 = ((str[0] & 0x1f) << 6) | (str[1] & 0x3f);
 	    next = 2;
@@ -117,7 +123,7 @@
 	  if (_table) {
 	    unsigned short h = _table[(ucs2 & 0x00ff)];
 	    if (h == 0) return OTHER;
-	    return ja_table[((h & 0xff00) >> 8)][(h & 0x00ff)]; // ucs2 -> jisx0208
+	    return t->ja_table[((h & 0xff00) >> 8)][(h & 0x00ff)]; // ucs2 -> jisx0208
 	  } 
 
 	  return OTHER;
diff -Nur mecab-0.81.orig/src/libmecab.cpp mecab-0.81/src/libmecab.cpp
--- mecab-0.81.orig/src/libmecab.cpp	2004-08-07 03:05:14.000000000 +0900
+++ mecab-0.81/src/libmecab.cpp	2005-04-19 19:27:23.000000000 +0900
@@ -48,6 +48,11 @@
   return tagger.parse (argc, argv);
 }
 
+int mecab_load_dictionary (int argc, char **argv)
+{
+  return (int) MeCab::SharedResourceOpen(argc, argv);
+}
+
 mecab_t* mecab_new (int argc, char **argv)
 {
    mecab_t *c = new mecab_t;
@@ -93,6 +98,28 @@
    return c;
 }
 
+mecab_t* mecab_new3 ()
+{
+   mecab_t *c = new mecab_t;
+   MeCab::Tagger *ptr = new MeCab::Tagger;
+   if (! c || ! ptr) {
+      errorStr = std::string ("mecab_new3(): bad alloc");
+      return 0;
+   }
+   c->allocated = 0;
+   if (! ptr->open ()) {
+     errorStr = std::string ("mecab_new3(): ");
+     errorStr += ptr->what ();      
+     delete ptr;
+     delete c; 
+     return 0;
+   }
+
+   c->ptr = ptr;
+   c->allocated = 1;
+   return c;
+}
+
 char* mecab_strerror (mecab_t *c)
 {
    if (! c || ! c->allocated) return const_cast<char *>(errorStr.c_str ());
diff -Nur mecab-0.81.orig/src/mecab.h mecab-0.81/src/mecab.h
--- mecab-0.81.orig/src/mecab.h	2005-03-20 22:18:57.000000000 +0900
+++ mecab-0.81/src/mecab.h	2005-04-19 19:27:23.000000000 +0900
@@ -92,8 +92,10 @@
   /* C interface */
   MECAB_DLL_EXTERN int           mecab_do                  (int, char**);
   MECAB_DLL_EXTERN int           mecab_make_dictionary     (char*, char*);
+  MECAB_DLL_EXTERN int           mecab_load_dictionary     (int, char**);
   MECAB_DLL_EXTERN mecab_t*      mecab_new                 (int, char**);
   MECAB_DLL_EXTERN mecab_t*      mecab_new2                (char*);
+  MECAB_DLL_EXTERN mecab_t*      mecab_new3                ();
   MECAB_DLL_EXTERN char*         mecab_strerror            (mecab_t*);
   MECAB_DLL_EXTERN void          mecab_destroy             (mecab_t*);
   MECAB_DLL_EXTERN int           mecab_lock                (mecab_t*);
@@ -134,6 +136,7 @@
   public:
     bool        open           (int, char**);
     bool        open           (const char*);
+    bool        open           ();
     bool        close          ();
     int         parse          (int, char**); // mecab_do
     const char* parse          (const char*, unsigned int = 0);
@@ -156,6 +159,7 @@
     Tagger  (const char*);
     ~Tagger();     
   };
+  bool SharedResourceOpen(int, char **);
 }
 
 #endif
diff -Nur mecab-0.81.orig/src/mmap.h mecab-0.81/src/mmap.h
--- mecab-0.81.orig/src/mmap.h	2004-03-08 16:40:53.000000000 +0900
+++ mecab-0.81/src/mmap.h	2005-04-23 18:44:53.000000000 +0900
@@ -92,6 +92,7 @@
     int    fd;
     int    flag;
 #endif
+    bool _no_unmap;
 
   public:
     T&       operator [] (unsigned int n)       { return *(text + n); }
@@ -234,14 +235,19 @@
 	  }
 	}
 	delete [] text;
-	text = 0;
 #endif    
+	text = 0;
       }
 
       return true;
     }
 
-    Mmap (): text(0), fd (-1) {}
+    void no_unmap()
+    {
+      _no_unmap = true;
+    }
+
+    Mmap (): text(0), fd (-1), _no_unmap(false) {}
 
      Mmap (const char *filename, const char *mode = "r"):
        text(0), fd (-1)
@@ -251,7 +257,7 @@
     }
 #endif      
 
-    ~Mmap () { this->close (); }
+    ~Mmap () { if (!_no_unmap) this->close (); }
   };
 }
 #endif
diff -Nur mecab-0.81.orig/src/tagger.cpp mecab-0.81/src/tagger.cpp
--- mecab-0.81.orig/src/tagger.cpp	2005-03-20 22:18:57.000000000 +0900
+++ mecab-0.81/src/tagger.cpp	2005-04-23 20:53:05.000000000 +0900
@@ -109,6 +109,94 @@
     return dicdir;
   }
 
+  static SharedResource *SoleSharedResource = NULL ;
+
+  SharedResource *lookupSharedResource(const char *prefix)
+  {
+    if (SoleSharedResource && SoleSharedResource->opened && !strcmp(prefix, SoleSharedResource->dicdir)) {
+      return SoleSharedResource;
+    }
+    return NULL;
+  }
+
+  SharedResource *lookupSharedResource(int charset)
+  {
+    if (SoleSharedResource && SoleSharedResource->opened && charset == SoleSharedResource->ct->charset) {
+      return SoleSharedResource;
+    }
+    return NULL;
+  }
+
+  bool SharedResourceOpen (int argc, char** argv)
+  {
+    if (SoleSharedResource) {
+      delete SoleSharedResource;
+    }
+    SoleSharedResource = new SharedResource;
+    return SoleSharedResource->open(argc, argv);
+  }
+
+  bool SharedResource::open(int argc, char** argv)
+  {
+    opened = true;close();
+    if (! param.open (argc, argv, long_options)) {
+      return false;
+    }
+    std::string rcfile = getDefaultRc (param);
+    if (! param.load (rcfile.c_str())) {
+      return false;
+    }
+    std::string dicrcfile = getDicRc (param, rcfile);
+    if (! param.load (dicrcfile.c_str())) {
+      return false;
+    }
+    const char *prefix = param.getProfileString("dicdir").c_str();
+    try {
+      JapaneseTokenizer tokenizer = JapaneseTokenizer (param);
+      ct = tokenizer.shareCharTable();
+
+      std::string dmapfileName = createFileName (std::string (prefix), DOUBLE_ARRAY_FILE);
+      if (! dmmap.open (dmapfileName.c_str())) throw std::runtime_error (dmmap.what());
+      std::string tmapfileName = createFileName (std::string (prefix), TOKEN_FILE);
+      if (! tmmap.open (tmapfileName.c_str())) throw std::runtime_error (tmmap.what());
+
+      std::string imapfileName = createFileName (std::string (prefix), POS_FILE);
+      if (! immap.open (imapfileName.c_str())) throw std::runtime_error (immap.what());
+
+      std::string mmapfileName = createFileName (std::string (prefix), CONNECTION_FILE);
+      if (! mmmap.open (mmapfileName.c_str())) throw std::runtime_error (mmmap.what());
+      size1 = mmmap[0]; size2 = mmmap[1]; size3 = mmmap[2];
+      if (size1 * size2 * size3 != (mmmap.size()-3))
+	    throw std::runtime_error ("file size is invalid");
+      matrix = mmmap.begin () + 3;
+      strcpy(dicdir, prefix);
+      opened = true;
+      return true;
+    }
+    catch (exception &e) {
+      dmmap.close();
+      tmmap.close();
+      immap.close();
+      return false;
+    }
+  }
+
+  bool SharedResource::close()
+  {
+    if (opened) {
+      param.clear();
+      tmmap.close();
+      immap.close();
+      dmmap.close();
+      mmmap.close();
+      opened = false;
+    }
+    return true;
+  }
+
+  SharedResource::SharedResource  (): opened(false) {};
+  SharedResource::~SharedResource () { close(); }
+
 #define TAGGER_INITILIZE  tokenizer(0), connector (0), build_all_lattice(0)
 
   class Tagger::Impl 
@@ -133,6 +221,7 @@
 
     bool        open           (int, char**);
     bool        open           (const char*);
+    bool        open           ();
     bool        close          ();
     int         parse          (int, char**);
     const char* parse          (const char*, unsigned int = 0);
@@ -196,6 +285,26 @@
     return open (param);
   }
    
+  bool Tagger::Impl::open ()
+  {
+    try {
+      close ();
+      if (!SoleSharedResource || !SoleSharedResource->opened) throw std::runtime_error (std::string ("SoleSharedResource is not opened"));
+      Param &param = SoleSharedResource->param;
+      build_all_lattice = (bool)param.getProfileInt ("build-all-lattice");
+      tokenizer = new JapaneseTokenizer (param);
+      connector = new Connector (param);
+      if (! viterbi.open (param, tokenizer, connector)) throw std::runtime_error (viterbi.what());
+      if (! writer.open (param))                        throw std::runtime_error (writer.what());
+      return true;
+    }
+    catch (exception &e) {
+      close ();
+      _what = std::string ("Tagger::Impl::open(): ") + e.what ();
+      return false;
+    }
+  }
+
   bool Tagger::Impl::open (Param &param)
   {
     try {
@@ -473,6 +582,7 @@
 
   bool        Tagger::open           (int argc, char** argv) { return _impl->open(argc, argv); }
   bool        Tagger::open           (const char* arg) { return _impl->open(arg); }
+  bool        Tagger::open           () { return _impl->open(); }
   bool        Tagger::close          () { return _impl->close(); }
   int         Tagger::parse          (int argc, char**argv)  { return _impl->parse(argc, argv); }
   const char* Tagger::parse          (const char* str, unsigned int len) { return _impl->parse(str,len); }
diff -Nur mecab-0.81.orig/src/viterbi.cpp mecab-0.81/src/viterbi.cpp
--- mecab-0.81.orig/src/viterbi.cpp	2004-08-07 03:05:14.000000000 +0900
+++ mecab-0.81/src/viterbi.cpp	2005-04-19 19:27:23.000000000 +0900
@@ -107,7 +107,7 @@
   {
     try {
       if (len >= alloc_size) {
-	do { alloc_size *= 2; } while (len > alloc_size);
+	do { alloc_size *= 2; } while (len >= alloc_size);
 	delete [] endNodeList;
 	delete [] lookupCache;
 	endNodeList = new Node * [alloc_size];
