for example. I just need a string. So I define

message TestMes{
   string test = 1;
}

then , I use it in python. and as comparison, I use a python string in 
another function.


@profile
def addstring():
  sss = []
  for i in range(1000):
    info = "aaa_anystring" + str(i)
    sss.append(info)


@profile
def addtestmes():
  sss = []
  for i in range(1000):
    test_mes = TestMes()
    sss.append(test_mes)

if __name__ == '__main__':
  reload(sys)
  addstring()
  addtestmes()

then execute with command
python  -m memory_profiler  test_mem.py

the result is 
Line #    Mem usage    Increment   Line Contents
================================================
   345   19.211 MiB    0.000 MiB   @profile
   346                             def addstring():
   347   19.211 MiB    0.000 MiB     sss = []
   348   19.219 MiB    0.008 MiB     for i in range(1000):
   349   19.219 MiB    0.000 MiB       info = "$sdf" + str(i)
   350   19.219 MiB    0.000 MiB       sss.append(info)



Filename: boarding.py

Line #    Mem usage    Increment   Line Contents
================================================
   354   19.219 MiB    0.000 MiB   @profile
   355                             def addtestmes():
   356   19.219 MiB    0.000 MiB     sss = []
   357   19.977 MiB    0.758 MiB     for i in range(1000):
   358   19.977 MiB    0.000 MiB       test_mes = TestMes()
   359   19.977 MiB    0.000 MiB       sss.append(test_mes)


As we can see, 1000 protobuf message use  0.758 MiB, in contrast, 1000 
string only use  0.008 MiB memory.
Note that I even has not assignment TestMes::test to avoid using memory.

why? 
and how can I use protobuf in python with less memory.
I want someone can help me.

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to