OLD | NEW |
| (Empty) |
1 /* | |
2 * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 * contributor license agreements. See the NOTICE file distributed with | |
4 * this work for additional information regarding copyright ownership. | |
5 * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 * (the "License"); you may not use this file except in compliance with | |
7 * the License. You may obtain a copy of the License at | |
8 * | |
9 * http://www.apache.org/licenses/LICENSE-2.0 | |
10 * | |
11 * Unless required by applicable law or agreed to in writing, software | |
12 * distributed under the License is distributed on an "AS IS" BASIS, | |
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 * See the License for the specific language governing permissions and | |
15 * limitations under the License. | |
16 */ | |
17 | |
18 package org.apache.tomcat.jni; | |
19 | |
20 import java.nio.ByteBuffer; | |
21 | |
22 /** Buffer | |
23 * | |
24 * @author Mladen Turk | |
25 */ | |
26 public class Buffer { | |
27 | |
28 /** | |
29 * Allocate a new ByteBuffer from memory | |
30 * @param size The amount of memory to allocate | |
31 * @return The ByteBuffer with allocated memory | |
32 */ | |
33 public static native ByteBuffer malloc(int size); | |
34 | |
35 /** | |
36 * Allocate a new ByteBuffer from memory and set all of the memory to 0 | |
37 * @param num Number of elements. | |
38 * @param size Length in bytes of each element. | |
39 * @return The ByteBuffer with allocated memory | |
40 */ | |
41 public static native ByteBuffer calloc(int num, int size); | |
42 | |
43 /** | |
44 * Allocate a new ByteBuffer from a pool | |
45 * @param p The pool to allocate from | |
46 * @param size The amount of memory to allocate | |
47 * @return The ByteBuffer with allocated memory | |
48 */ | |
49 public static native ByteBuffer palloc(long p, int size); | |
50 | |
51 /** | |
52 * Allocate a new ByteBuffer from a pool and set all of the memory to 0 | |
53 * @param p The pool to allocate from | |
54 * @param size The amount of memory to allocate | |
55 * @return The ByteBuffer with allocated memory | |
56 */ | |
57 public static native ByteBuffer pcalloc(long p, int size); | |
58 | |
59 /** | |
60 * Allocate a new ByteBuffer from already allocated memory. | |
61 * <br>Allocated memory must be provided from call to the | |
62 * Stdlib.alloc or Stdlib.calloc methods. | |
63 * @param mem The memory to use | |
64 * @param size The amount of memory to use | |
65 * @return The ByteBuffer with attached memory | |
66 */ | |
67 public static native ByteBuffer create(long mem, int size); | |
68 | |
69 /** | |
70 * Deallocates or frees a memory block used by ByteBuffer | |
71 * <br><b>Warning :</b> Call this method only on ByteBuffers | |
72 * that were created by calling Buffer.alloc or Buffer.calloc. | |
73 * @param buf Previously allocated ByteBuffer to be freed. | |
74 */ | |
75 public static native void free(ByteBuffer buf); | |
76 | |
77 /** | |
78 * Returns the memory address of the ByteBuffer. | |
79 * @param buf Previously allocated ByteBuffer. | |
80 */ | |
81 public static native long address(ByteBuffer buf); | |
82 | |
83 /** | |
84 * Returns the allocated memory size of the ByteBuffer. | |
85 * @param buf Previously allocated ByteBuffer. | |
86 */ | |
87 public static native long size(ByteBuffer buf); | |
88 | |
89 } | |
OLD | NEW |