.
D 2007-02-21T21:44:38
J assignee dkf
J cmimetype text/plain
J comment There\sis\sno\sway\sto\sefficiently\smodify\sa\sByteArray,\seither\sby\sappending\sdata\sto\sthe\send\sor\sby\sremoving\sdata\sfrom\sthe\sfront\s(as\smight\sbe\suseful\sfor\sa\sbinary\sstream\sbuffer).\s\s\n\nConsider\sone\stask\sto\sread\sfrom\sa\sbinary\ssocket\sand\sbuffer\sthe\sdata\sand\sanother\sto\sdecode\scounted\sstrings\sfrom\sthe\sfront\sof\sthe\sbinary\sstring:\n\n\s\svariable\sbuffer\n\s\sproc\sread_handler\s{sock}\s{\n\s\s\s\svariable\sbuffer\n\s\s\s\sappend\sbuffer\s[read\s$sock]\n\s\s}\n\s\s\n\s\sproc\sprocess_buffer\s{}\s{\n\s\s\s\svariable\sbuffer\n\s\s\s\sif\s{[string\slength\s$buffer]\s>\s0}\s{\n\s\s\s\s\s\sbinary\sscan\s$buffer\s"I"\sdlen\n\s\s\s\s\s\sbinary\sscan\s$buffer\s"x4\sa$dlen"\sdata\n\s\s\s\s\s\sbinary\sscan\s$buffer\s"x4\sx$dlen\sa*"\sbuffer\n\s\s\s\s}\n\s\s}\n\nThe\sfirst\sproblem\sis\sthat\s"append"\sonly\soperates\son\sstring\sreps,\swhich\srequires\sthe\sentire\sByteArray\sto\sbe\sscanned\sand\sconverted\sto\sthe\sutf-8\s(or\sunicode)\sencoding.\s\s(append\salso\sappears\sto\sunset\sthe\slength\sof\sthe\sstring,\smeaning\sthat\sa\ssubsequent\s"string\slength"\smust\srecompute\sit).\n\nThe\ssecond\sproblem\sis\sthat\sscanning\sa\sfew\sbytes\sfrom\sthe\sfront\sof\sthe\sByteArray\sand\sthe\smodifying\sthe\soriginal\smeans\sthat\sthe\sentire\sByteArray\sneeds\sto\sbe\scopied.\s\s(maintaining\sa\sseparate\scursor\sis\sefficient\sbut\sclumsy).\n\n"append"\sshould\sprobably\sdo\sthe\ssensible\sthing\sand\sappend\sByteArrays\sefficiently\s(as\swell\sas\ssetting\sthe\slength\scorrectly),\sbut\ssince\sthis\sis\sspecifically\sdealing\swith\sbinary\sstrings\sit\smay\smake\ssense\sto\simplement\sthese\soperations\sentirely\sas\ssubcommands\sof\s"binary".\n\nI\ssuggest\n\s\sbinary\sappend\svarName\s?arg\sarg\s...?\nto\sappend\sthe\sByteArray\svalues\sof\sall\sargs\sto\sthe\snamed\sbinary\svalue;\sand\s\n\s\sbinary\sdscan\svarName\sformatString\s?varName\svarName\s...?\ndscan\s=\s"destructive\sscan",\swith\sfunctionality\sidentical\sto\s"binary\sscan"\sexcept\sthat\sit\stakes\sa\svarName\sinstead\sof\sa\sstring,\sand\sit\schanges\sthe\sByteArray\sobject\sto\shave\sthe\sstart\soffset\sat\sthe\send\sof\sthe\sformat\sarguments\s\s\sThis\swould\sneed\sthe\sByteArray\sobject\sto\sstore\san\soffset\sindicating\swhere\sthe\sstart\sof\sthe\sdata\sis.\s\sThe\slength\scomputation\sof\sa\sByteArray\sobject\swould\sneed\sto\sbe\schanged\sto\suse\sthe\soffset\sbut\sthis\sshould\sbe\scontained\swithin\stclBinary.c.\s\sThe\sdestructive\soperation\scould\seither\sjust\schange\sthe\soffset\sor\sactually\smodify\sthe\sunderlying\sbytes.\s\sIf\sit\sworks\sby\schanging\sthe\soffset\sthen\sthere\swould\sneed\sto\sbe\ssome\spoint\sat\swhich\sit\swould\sactually\smodify\sthe\sbytes\sbecause\sthe\smemory\sbetween\sthe\sstart\sof\sthe\sbytes\sand\sthe\soffset\sis\swasted;\sthis\spoint\scould\sbe\ssome\shardcoded\smaximum\sor\sa\sheuristic\smeasure\sbased\son\sthe\soverall\ssize\sof\sthe\sdata.\s\s(i.e.,\sif\sthe\swasted\sspace\sis\slarger\sthan\sthe\sused\sspace,\scopy\sthe\slive\sdata\sto\sthe\sbeginning\sof\sthe\sallocated\sspace,\slimiting\sthe\swasted\sspace\sto\s100%\soverhead\sand\susing\sa\snon-overlapping\smove\soperation).\n\nAnother\smethod\sfor\smodifying\sa\sbinary\sobject\scould\sbe\n\s\sbinary\sset\svarName\sformatSting\s?arg\sarg\s...?\nwhich\swould\sbe\ssomething\slike\s"binary\sformat"\sworking\son\san\sexisting\sbytearray.
J foundin obsolete:\s8.4.14
J is_private 0
J priority 5\sMedium
J resolution None
J status Open
J submitter dvrsn
J subsystem 12.\sByteArray\sObject
J title cannot\sefficiently\smodify\sa\sByteArray
J type RFE
K 1665628fffffffffffffffffffffffffffffffff
U dvrsn
Z 984823768912694efacc82d72d49761f