implementation

Why is Linux memmove() implemented the way it is?

泄露秘密 提交于 2019-12-18 03:11:01
问题 From the Linux manpage for memmove(3) The memmove() function copies n bytes from memory area src to memory area dest. The memory areas may overlap: copying takes place as though the bytes in src are first copied into a temporary array that does not overlap src or dest, and the bytes are then copied from the temporary array to dest. Instead of allocating a temporary array and copy the values twice we could just do the following: void *my_memmove(void *dest, const void *src, size_t n) { signed

Does the JVM create a mutex for every object in order to implement the 'synchronized' keyword? If not, how?

我与影子孤独终老i 提交于 2019-12-18 02:15:32
问题 As a C++ programmer becoming more familiar with Java, it's a little odd to me to see language level support for locking on arbitrary objects without any kind of declaration that the object supports such locking. Creating mutexes for every object seems like a heavy cost to be automatically opted into. Besides memory usage, mutexes are an OS limited resource on some platforms. You could spin lock if mutexes aren't available but the performance characteristics of that are significantly different

How is reference to java object is implemented?

依然范特西╮ 提交于 2019-12-17 17:07:04
问题 Is pointer is just used for implementing java reference variable or how it is really implemented? Below are the lines from Java language specification 4.3.1 Objects An object is a class instance or an array. The reference values (often just references) are pointers to these objects, and a special null reference, which refers to no object. Does that mean it is pointer all the time? 回答1: In modern JVMs, references are implemented as an address. Going back to the first version of HotSpot (and a

How to change the implementation (detour) of an externally declared function

▼魔方 西西 提交于 2019-12-17 04:28:22
问题 I have a third party function function DataCompare(const S1, S2: string; APartial: Boolean): Boolean; begin ... end; It is used in another third party unit. I wish to replace the body of the function at runtime with another new implementation. Is this possible? I guess there will be a need of some hack (ala VirtualMemoryUnprotect). A non-assembler solution is very welcome. 回答1: Yes you can do that, using the ReadProcessMemory and WriteProcessMemory functions to patch the code of the current

Implementing merge sort in java 7

喜夏-厌秋 提交于 2019-12-14 03:16:51
问题 I have a problem with implementation of merge sort in java. I am looking for the error almost week unfortunately without result. ArrayList at the entrance is the same as the output. import java.util.ArrayList; import java.util.Scanner; public class MergeSort { private ArrayList<Integer> basicArrayList = new ArrayList<Integer>(); ArrayList<Integer> arrayListA = new ArrayList<Integer>(); ArrayList<Integer> arrayListB = new ArrayList<Integer>(); Scanner input = new Scanner(System.in); private

where python store global and local variables?

删除回忆录丶 提交于 2019-12-14 02:26:59
问题 Almost same as question Where are the local, global, static, auto, register, extern, const, volatile variables are stored?, the difference is this thread is asking how Python language implement this. 回答1: Of all those, Python only has "local", "global" and "nonlocal" variables. Some of those are stored in a Dictionary or dictionary like object, which usually can be explicitly addressed. "global" : Actually "global" variables are global relatively to the module where they are defined -

Interface inheritance consistency

蹲街弑〆低调 提交于 2019-12-14 01:36:43
问题 First look at this code: class Program { static void Main(string[] args) { var x =(Base) new Derived(); ((IMethod)x).DoWork(); Console.ReadKey(); } } interface IMethod { void DoWork(); } abstract class Base : IMethod { void IMethod.DoWork() { Console.WriteLine("Base.DoWork"); } } class Derived : Base, IMethod { public void DoWork() { //here I where I want to call base.DoWork(); Console.WriteLine("Derived.DoWork"); } } Output: Derived.DoWork Desired: Base.DoWork Derived.DoWork I'm dealing with

Deep copying linked list

断了今生、忘了曾经 提交于 2019-12-13 09:13:06
问题 I'm trying to implement a stack on the heap using a linked list. However, for using the 'list' function I need to create a deep copy of the linked list, which i'm not completely sure how it's done. Here's a part of my code: class Stack { private: struct Node { int data; Node *next; }; Node *stackTop; public: Stack() {stackTop = nullptr;} Stack(const Stack& original); ~Stack(); bool isEmpty() const; int top() const; int pop(); void push(int newItem); }; Stack::~Stack() { delete stackTop; }

Curious problem involving generics and static methods

非 Y 不嫁゛ 提交于 2019-12-13 02:38:58
问题 I have a number of data classes, which share an abstract base class so i can work with them generically (sort of). They each have a static method called Lerp, which i use frequently along with a couple of other lines. I wanted to refactor this out into a method because of DRY,but it seems there's no way to do so. How do i get around this? Can provide code if neccessary. The code is basically this: XmlNode mineDataMin = mineDataMaster.SelectSingleNode("DataMinimum"); XmlNode mineDataMax =

Implementing large interface

牧云@^-^@ 提交于 2019-12-12 23:14:50
问题 I am using a library that has a large interface interface IOrder{ cutomerId: number; deliveryAddress1: string; // and lots of properties... } And I want to implement a class extending it. Just want to confirm that it is necessary to re-declare all the properties. class Order implements IOrder{ cutomerId: number; /* error: Class 'Order' incorrectly implements interface 'IOrder'. Property 'deliveryAddress1' is missing in type 'Order' */ } Of course, methods need to be implemented but I find re