首页 \ 问答 \ 插入缓冲区的有效方法(Efficient way to insert into buffer)

插入缓冲区的有效方法(Efficient way to insert into buffer)

假设我将一个流读入缓冲区,并且我希望在此缓冲区中进行多次插入。 是否有一些有效的帮助对象我可以调用来帮助解决这个问题。 假设我想在位置100处插入10个字节的长度,然后在位置500处插入20个字节的长度(在插入前10个字节后现在将为510)。 我所追求的是跟踪多次插入时实际插入的位置(否则我必须通过我已插入的内容移动所有地址)。

滚动我自己很简单,但我想知道我是否在这里重新发明轮子,这已经包含在某些.NET构造中了?


Let's say I read a stream into a buffer, and I want to make multiple insertions into this buffer. Is there some efficient helper object I can call to help with this. Say if I want to make an insertion of 10 bytes length at position 100, then 20 bytes length into position 500 (which would now be 510 after inserting the first 10 bytes). What I'm after is something to keep track of where to actually make the insertions when inserting multiple times (otherwise I have to shift all address by the what I've already inserted).

It would be simple to roll my own, but I was wondering if I'm reinventing the wheel here, and this is already included in some .NET construct?


原文:https://stackoverflow.com/questions/27851959
更新时间:2023-08-19 20:08

最满意答案

如果你定义<T extends Main> T foo(); 在Type Main你不能只返回this ,因为T可能是Main的子类型, Main当然不是。 所以如果你有MainSubType m = new Main().foo(); 编译器想要将T作为MainSubType但面对它只是Type Main ,所以你必须用硬解析它,我不能在这里推荐但是你去的方式<T extends Main> T foo(){return (T) this} 。 如果你这样做,你应该能够编译其余的。

如果它不能与foo()中的(T)-cast一起使用,则需要提供更多的上下文/代码。


If you define <T extends Main> T foo(); in Type Main you cant just return this, because T might be a subtype of Main, which Main of course isn't. So if you have MainSubType m = new Main().foo(); the Compiler wants to induce T as MainSubType but in face it is only of Type Main, so you have to parse it the hard way, which i cannot recommend here but that is how you go <T extends Main> T foo(){return (T) this}. If you do it like that you should indeed be able to compile the rest.

If it doesn't work with the (T)-cast in foo(), you will need to provide more context/code.

相关问答

更多
  • 你能告诉我们你如何运行你的代码(例如命令行,如果是这样,什么是类路径),以及splash.png的所有位置在你的文件夹结构中的位置? 该文件需要位于类路径上,因为它似乎是此代码加载图像的位置。 http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/desktop/com/jme3/system/JmeDesktopSystem.java?spec=svn10038&r=10038#112 String iconPa ...
  • List List应该被理解为“一个元素类型是Suv超类型的列表” 。 现在,让我们看看这两行: list = new ArrayList(); list.add(a); // where a is an Automobile 第一行是好的,因为ArrayList确实是“一个元素类型是Suv超类型的列表” 。 但是让我们读出第二行:将一些Automobile添加到一个列表,其元素类型是超级类型的Suv 。 ...
  • 这里涉及两种截然不同的类型: 变量的类型; 变量引用的对象的类型。 变量的类型与它当前碰巧指向的对象的类型无关,反之亦然,对象的类型不取决于访问它的变量的类型。 因此,当您将一个对象分配给另一个不同的变量时,其类型不受影响。 所以, 变量 cd的类型是C ; 它引用的对象的类型是D There are two distinct types involved here: type of the variable; type of the object referred to by the variable. ...
  • 您可能知道, split方法使用正则表达式模式来拆分字符串: 第一个案例\d使用数字数字作为分隔符将其拆分 第二种情况\b使用单词边界拆分它,所以你实际上有一个空字符串和整个余数 第三种情况\a是一个特殊字符,它不存在于您要拆分的字符串中,因此您只需要一个标记 看看这里的所有正则表达式选项。 The split method, as you may know, uses a regex pattern to split the string: first case \d splits it using nu ...
  • 如果你定义 T foo(); 在Type Main你不能只返回this ,因为T可能是Main的子类型, Main当然不是。 所以如果你有MainSubType m = new Main().foo(); 编译器想要将T作为MainSubType但面对它只是Type Main ,所以你必须用硬解析它,我不能在这里推荐但是你去的方式 T foo(){return (T) this} 。 如果你这样做,你应该能够编译其余的。 如果它不能与foo() ...
  • //Intuitively I would expect this to mean that test is set containing objects //that subclass AbstractGroup Set test; 不,这意味着它是一组特定的? 它扩展了AbstractGroup。 你和编译器都没有办法知道那是什么? 是的,所以你无法向该组添加任何东西。 您可以将该集的值分配给AbstractGroup类型的变量,但不能反过来。 相反 ...
  • 该行可以连接obj1 =(可关联)object1; 似乎创建了可关联类型的对象 Relatable 。该行创建可Relatable类型的引用 (obj1)并将其分配给object1 。 为了使其工作, object1必须转换为(接口)类型Relatable 。 这里没有创建新的对象。 这是否意味着实现Relatable的任何东西都可以调用findLargest()? 是。 如果是这样,为什么说这两个对象都属于同一个类? 它与isLargerThan()的实现有关。 由于实现可Relatable接口的任何类都 ...
  • 解决方案,双引号classpath参数。 示例: -classpath "*"这在命令行和bash脚本中都是必需的。 随后的附录: 此外,请注意-classpath "~/folder/*"失败但-classpath ~/folder/"*"是好的。 引用通配符但不引用~ 。 您似乎需要操作系统来解释~但是您需要引用*通配符,因为您希望将其传递给java以便以Java方式进行扩展。 另请注意,您不应该要求java扩展*.jar因为这会产生意想不到的结果。 Java规范说正确的通配符只是* 。 Solutio ...
  • 鉴于这条线: for (int i = 0; i < buttons.length; i++) { for语句在值0处创建变量i 。 然后它为数组buttons中的每个值(列表结构)在{和}之间运行一次代码,每次增加变量i 。 第一次通过,行if (i == 2)将失败,因为i仍然是0 ,然后在else语句之后调用代码。 这会添加一个带有文本Cls的按钮。 第三次通过代码变量i将为2 (因为它从零开始),然后它将在if (i == 2)之后运行 - 因为这就是它的作用。 然后它将添加一个空标签(数组but ...
  • 在普通的Java中,是的, Integer是一个Number 。 但在泛型中, List不是List 。 要查看原因,请尝试将List分配给List ,看看会发生什么: List numberList = new ArrayList(); // not allowed // This would have been allowed, even though the argument is // boxed ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。